[NCLUG] Testing memory pressure
Bob Proulx
bob at proulx.com
Thu Jan 13 10:04:19 MST 2011
grant at amadensor.com wrote:
> I want to test how an application reacts to being starved for resources.
>
> I have some pretty good ideas about how to create an artificial I/O load
> and a CPU load. Does anyone have a good idea for how to (from something
> quick like shell or PERL) use a lot of memory so that things start to swap
> out?
Two ideas:
$ apt-cache show stress
Description: A tool to impose load on and stress test a computer system
'stress' is a tool that imposes a configurable amount of CPU, memory, I/O,
or disk stress on a POSIX-compliant operating system and reports any errors
it detects.
.
'stress' is not a benchmark. It is a tool used by system administrators to
evaluate how well their systems will scale, by kernel programmers to evaluate
perceived performance characteristics, and by systems programmers to expose
the classes of bugs which only or more frequently manifest themselves when
the system is under heavy load.
Second you could use a very simple program to hog memory at whatever
value you want. Here is a very simple one. Originally written to hog
memory and push a machine into vm thrashing.
Bob
#include <stdlib.h>
#include <stdio.h>
main()
{
char *array;
int i, mem_size;
printf("Enter memory size to hog in megabytes: ");
scanf("%d",&mem_size);
array = malloc(mem_size * 1024 * 1024);
if (array == 0)
{
fprintf(stderr,"Error: unable to malloc: out of memory\n");
exit(1);
}
i = 0;
for (;;) {
for (i = i; i < (mem_size * 1024 * 1024); i += 1027) {
*(array + i) = 'f';
}
i = i - (mem_size * 1024 * 1024);
}
return 0;
}
More information about the NCLUG
mailing list