Linux: How to put a load on system memory?

后端 未结 12 2066
清酒与你
清酒与你 2021-02-10 07:54

I\'m working on a small function, that gives my users a picture of how occupied the CPU is.

I\'m using cat /proc/loadavg, which returns the well known 3 num

相关标签:
12条回答
  • 2021-02-10 08:27

    Use "memtester" to do your memory regression tests in Linux.

    0 讨论(0)
  • 2021-02-10 08:28

    I took this program and modify the line: mem = 1024*1024*512; //512 mb to say this: mem = 1*1024*1024*1024; //1 GB and compile it.

    $ gcc iss_mem.c -o iss_mem

    And write a bash wrapper around the compiled version of the C program above. It helps me generate a lot of memory load in my server.

    #!/bin/bash
    # Author: Mamadou Lamine Diatta
    #         Senior Principal Consultant / Infrastructure Architect
    # Email:  diatta at post dot harvard dot edu
    # --------------------------------------------------------------------------------------
    # *************************************************************************************
    
    memsize_kb=`grep -i MemTotal /proc/meminfo | awk '{print $2}'`
    MemTotal=$(($memsize_kb*1024))
    for i in `seq 1 50`
    do
    
            echo "`date +"%F:%H:%M:%S"` ----------------- Running [ $i ] iteration(s)"
            MemToAlloc=$((1*1024*1204*1204))
                # 1Gb of memory per iss_mem call
            TRESHOLD=$(($MemTotal/$MemToAlloc))
                 # We are not supposed to make the system
                 # run out of memory
            rand=1000
                # High enough to force a new one
            while (( $rand > $TRESHOLD ))
            do
                    rand=$(($RANDOM/1000))
            done
            if [ $rand -eq 0 ]
            then
                    rand=1
            fi
    
            echo `date +"%F:%H:%M:%S"` Running $rand iss_mem in parallel ...
            for j in `seq 1 $rand`
            do
                 ${ISSHOME}/bin/iss_mem > /dev/null &
                    # NOTE: gcc iss_mem.c -o iss_mem
            done
    
            sleep 180
            jobs -p
            kill `jobs -p`
    
            sleep 30
    
    
    done
    # -------------------------------------------------------------------------------------
    # *************************************************************************************
    
    0 讨论(0)
  • 2021-02-10 08:29

    you can stress utility, as it is a workload generator tool designed to subject your system to a configurable measure of CPU, memory, I/O and disk stress.

    To run 1 vm stressor using 1GB of virtual memory for 60s, enter:

    stress --vm 1 --vm-bytes 1G --vm-keep -t 60s

    0 讨论(0)
  • 2021-02-10 08:30

    1G memory

    python -c 'a="a"*1024**3;raw_input()'
    
    0 讨论(0)
  • 2021-02-10 08:41
    mark@localhost$ time pi 1048576 | egrep '.*total$'
    

    Is a simple benchmarking command that will give your cpu a rousting, post your times :D

    0 讨论(0)
  • 2021-02-10 08:41
    while true;
        do openssl speed;
    done
    

    also the stress program will let you load the cpu/mem/disk to the levels you want to simulate:

    • http://weather.ou.edu/~apw/projects/stress/

    stress is a deliberately simple workload generator for POSIX systems. It imposes a configurable amount of CPU, memory, I/O, and disk stress on the system. It is written in C, and is free software licensed under the GPLv2.

    to maintain a particular level of cpu utilization, say 30%, try cpulimit:

    • http://cpulimit.sourceforge.net/

    it will adapt to the current system environment and adjust for any other activity on the system.

    there's also a patch to the kernel for native cpu rate limits here: http://lwn.net/Articles/185489/

    0 讨论(0)
提交回复
热议问题