Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to simply simulate system load on Linux

Shulou Source: shulou.com Published: 2022-06-01 12:29:38 10月28日 Update

This article mainly explains "how to simply simulate system load on Linux". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to simply simulate system load on Linux".

CPU

The following command creates a CPU load by compressing random data and sending the results to / dev/null:

Cat / dev/urandom | gzip-9 > / dev/null

If you want more load, or if the system has multiple cores, all you need to do is compress and decompress the data, like this:

Cat / dev/urandom | gzip-9 | gzip-d | gzip-9 | gzip-d > / dev/null

Press CTRL+C to terminate the process.

Memory footprint

The following command reduces the total amount of memory available. It is achieved by creating a file system in memory and writing files to it. You can use as much memory as you want, just write more files into it.

First, create a mount point, and then mount the ramfs file system:

Mkdir zmount-t ramfs ramfs z /

The second step is to create a file in this directory using dd. Here we create a 128m file:

Dd if=/dev/zero of=z/file bs=1M count=128

The size of the file can be modified by the following operators:

Bs= block size. It can be any number followed by B (for bytes), K (for KB), M (for MB), or G (for GB).

How many blocks does count= have to write?

Disk IPUBO

The way to create disk I _ par O is to create a file first, and then use the for loop to keep copying it.

The following uses the command dd to create a 1G file with all zeros:

Dd if=/dev/zero of=loadfile bs=1M count=1024

The following command performs 10 operations with a for loop. Loadfile is copied each time to overwrite loadfile1:

For i in {1... 10}; do cp loadfile loadfile1; done

Adjust the run time by modifying the second parameter in {1... 10}. (LCTT translation note: the default cp command used on your Linux system is likely to be an alias for cp-I, in which case overriding will prompt you to enter y to confirm, you can use the cp command with the-f argument to override this behavior, or directly with the / bin/cp command. )

If you want to keep running until you press CTRL+C to stop, run the following command:

While true; do cp loadfile loadfile1; done thank you for reading, the above is the content of "how to simply simulate system load on Linux". After the study of this article, I believe you have a deeper understanding of how to simply simulate system load on Linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: File system command memory size learning running content parameter situation copy data method more disk load loop creation alias just need Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL vpn Xiaomi macOS