Saturday, 26 October 2013

Performance modelling of a linux system using fork bomb


Today I will be showing you a simple way to measure the memory allocation capacity of the system.

Unlike in case of httpperf my method doesn't rely on the network based requests to load the system

I will be loading the system with processes by running a shell script in each of the guest operating systems(If the system under test is a server virtualized system) The shell scripts can be controlled remotely using telnet.

I would like to measure active memory, free memory, swap memory, inactive memory while loading the system with processes.

The idea here is to get all the required performance metrics from /proc/meminfo while forking processes. For example at one particular instance on my system
/proc/meminfo:



MemTotal:        2945376 kB
MemFree:          765960 kB
Buffers:          144004 kB
Cached:           993792 kB
SwapCached:            0 kB
Active:           979460 kB
Inactive:         995496 kB
Active(anon):     838076 kB
Inactive(anon):   178496 kB
Active(file):     141384 kB
Inactive(file):   817000 kB
Unevictable:          84 kB
Mlocked:              84 kB
SwapTotal:       6261756 kB
SwapFree:        6261756 kB
Dirty:               800 kB
Writeback:             0 kB
AnonPages:        837144 kB
Mapped:           213612 kB
Shmem:            179416 kB
Slab:              91864 kB
SReclaimable:      60272 kB
SUnreclaim:        31592 kB
KernelStack:        4000 kB
PageTables:        39688 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     7734444 kB
Committed_AS:    4186924 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      556904 kB
VmallocChunk:   34359177692 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       63488 kB
DirectMap2M:     2942976 kB
=======

Also If we want to track any process, the folder /proc has details about each and every process running on the system.

Regarding loading the system:

There are two types of loads . Linear load  and Exponential load
In linear load, one process forks another process and waits for it to exit. The spawned process forks another process and waits for its child to exit. This keeps going on and on till the system eventually fails. To load the system with linear load we ran the following shell script:

#!/bin/bash
$0 &
wait

"$0 &" will run the same script in the background and 'wait' will make the current process to wait till the spawned process returns.

Similarly exponential load can be given by spawning 2 processes instead of one.
#!/bin/bash
$0 &
$0 &
wait

Collecting data:
The following code has to be embedded into the above script
# <epoch time> <PID> <Memory free> <swap free> <active memory> <inactive memory>

string=`date +%s`" "$$
i=`cat /proc/meminfo| grep "MemFree:"`
string=$string" "`expr "$i" : ".* \(.*\) kB"`
i=`cat /proc/meminfo| grep "SwapFree:"`
string=$string" "`expr "$i" : ".* \(.*\) kB"`
i=`cat /proc/meminfo| grep "Active:"`
string=$string" "`expr "$i" : ".* \(.*\) kB"`
i=`cat /proc/meminfo| grep "Inactive:"`
string=$string" "`expr "$i" : ".* \(.*\) kB"`
echo $string>>log
Sample output for linear load:
Sample output for exponential load:

No comments:

Post a Comment