zoukankan      html  css  js  c++  java
  • linux系统生成负载

    Simulate System Loads
    Sysadmins often need to discover how the performance of an application is affected when the system is under certain types of load. This means that an artificial load must be re-created. It is, of course, possible to install dedicated tools to do this but this option isn’t always desirable or possible.

    Every Linux distribution comes with all the tools needed to create load. They are not as configurable as dedicated tools but they will always be present and you already know how to use them.

    CPU
    The following command will generate a CPU load by compressing a stream of random data and then sending it to /dev/null:

    cat /dev/urandom | gzip -9 > /dev/null
    If you require a greater load or have a multi-core system simply keep compressing and decompressing the data as many times as you need e.g.:

    cat /dev/urandom | gzip -9 | gzip -d | gzip -9 | gzip -d > /dev/null
    An alternative is to use the sha512sum utility:

    sha512sum /dev/urandom
    Use CTRL+C to end the process.

    RAM
    The following process will reduce the amount of free RAM. It does this by creating a file system in RAM and then writing files to it. You can use up as much RAM as you need to by simply writing more files.

    First, create a mount point then mount a ramfs filesystem there:

    mkdir z
    mount -t ramfs ramfs z/
    Then, use dd to create a file under that directory. Here a 128MB file is created:

    dd if=/dev/zero of=z/file bs=1M count=128
    The size of the file can be set by changing the following operands:

    bs= Block Size. This can be set to any number followed B for bytes, K for kilobytes, M for megabytes or G for gigabytes.
    count= The number of blocks to write.
    Disk
    We will create disk I/O by firstly creating a file, and then use a for loop to repeatedly copy it.

    This command uses dd to generate a 1GB file of zeros:

    dd if=/dev/zero of=loadfile bs=1M count=1024
    The following command starts a for loop that runs 10 times. Each time it runs it will copy loadfile over loadfile1:

    for i in {1..10}; do cp loadfile loadfile1; done
    If you want it to run for a longer or shorter time change the second number in {1..10}.

    If you prefer the process to run forever until you kill it with CTRL+C use the following command:

    while true; do cp loadfile loadfile1; done

  • 相关阅读:
    主成分分析PCA(1)
    机器人操作系统入门(七)rospy客户端库
    线性代数的本质(Essense of Linear Algebra)——3Blue1Brown
    机器人操作系统入门(六)roscpp客户端库
    《机器人操作系统(ROS)浅析》肖军浩译
    机器人操作系统入门(五)常用工具
    Python学习(八)Matlab和Numpy异同
    机器人操作系统入门(四)ROS通信架构
    机器人操作系统入门(三)ROS通信架构
    机器人操作系统入门(二)ROS文件系统
  • 原文地址:https://www.cnblogs.com/zhoubiyu/p/14597993.html
Copyright © 2011-2022 走看看