Run my application in a simulated low memory, slow CPU environment
Asked Answered
D

9

8

I want to stress-test my application this way, because it seems to be failing in some very old client machines.

At first I read a bit about QEmu and thought about hardware emulation, but it seems a long shot. I asked at superuser, but didn't get much feedback (yet).

So I'm turning to you guys... How do you this kind of testing?

Druggist answered 22/7, 2011 at 12:47 Comment(3)
Some tips in #1929034Eurydice
That talks about reducing CPU speed, what about RAM? I think my best choice would be to put together a really crappy machine myselfDruggist
The big UNIX question: unix.stackexchange.com/questions/99334/…Penguin
C
7

I'm not sure about slowing a CPU but if you use a virtual machine, like VMWare, you can control how much RAM is actually used. I run it on a MBP at home with 8GB and my WinXP VM is capped at 1.5 GB RAM.

EDIT: I just checked my version of VMWare and I can control the number of cores it can use. It's definitely not the same as a slower CPU but it might highlight some issues for you.

Since it's not entirely clear that your app is failing because of the old hardware or the old OS, a VM client should allow you to test various versions of OSes rather quickly. It came in handy for me a few years back when I was trying to get a .Net 2.0 app to run on Win98 (it can be done though I don't remember how I got it working...).

Certifiable answered 22/7, 2011 at 19:48 Comment(0)
C
3

Virtual Box is a free virtual machine similar to VMWare. It also has the capacity to reduce available memory. It can restrict how many CPUs are available, but not how fast those CPUs are.

Cleavland answered 30/7, 2011 at 4:13 Comment(0)
S
3

Try cpulimit, most distro includes it (Ubuntu does) http://www.digipedia.pl/man/doc/view/cpulimit.1

Skyeskyhigh answered 1/8, 2011 at 12:10 Comment(0)
R
2

If you want to lower the speed of your cpu you can easily do this by modifying a fork bomb program

int main(){
     int x=0;
     int limit = 10

     while( x < limit ){

         int pid = fork();
         if( pid == 0 )
                 while( 1 ){}
         else
             x++;
    }

}

This will slow down your computer quite quickly, you may want to change the limit variable to a higher number. I must warn you though this can be dangerous, because if implemented wrong you could fork bomb your system leaving it useless unless you restart it. Read this first if you don't understand what this code will do.

Rearward answered 27/7, 2011 at 2:27 Comment(0)
H
2

On POSIX (Unix) systems you can apply run limits to processes (that is, to executions of a program). The system call to do this is called setrlimit(), and most shells enable you to use the ulimit built-in to set them from the command-line (plain POSIX ulimit is not very useful). Using these you can run a program with low limits to simulate a smaller computer.

POSIX systems also provide a nice command for running a program at lower CPU priority, which can simulate a slower CPU if you also ensure there is another CPU intensive progam running at the same time.

Holmium answered 29/7, 2011 at 12:26 Comment(1)
See also #4689759Holmium
M
1

I think it's pretty unlikely that cpu speed is going to exercise very many bugs; On the other hand, it's much more likely for different cpu features to matter. Many VM implementations provide ways of toggling on and off certain cpu features; qemu in particular permits a high level of control over what's available to the CPU.

Mouth answered 31/7, 2011 at 16:3 Comment(1)
Ummm... not sure how much concurrent programming you do, but many race conditions depend entirely on the speed of the hardware you execute them on.Gobo
L
1

Think outside the box. Which application of the ones you use regularly does this? A debugger of course! But, how can you achieve such a behavior, to emulate a low cpu?

The secret to your question is asm _int 3. This is the assembly "pause me" command that is send from the attached debugger to the application you are debugging.

More about int 3 to this question.

You can use the code from this tool to pause/resume your process continuously. You can add an interval and make that tool pause your application for that amount of time.

The emulated-cpu-speed would be: (YourCPU/Interval) -0.00001% because of the signaling and other processes running on your machine, but it should do the trick.

About the low memory emulation: You can create a wrapper class that allocates memory for the application and replace each allocation with call to this class. You would be able to set exactly the amount of memory your application can use before it fails to allocate more memory.

Something such as: MyClass* foo = AllocWrapper(new MyClass(arguments or whatever)); Then you can have the AllocWrapper allocating/deallocating memory for you.

Lamanna answered 31/7, 2011 at 23:25 Comment(0)
P
0

On Linux, you can use ulimit as Raedwald said. On Windows, you can use the SetProcessWorkingSetSize system call. But these only set a limit on a per process basis. In reality, parts of the system will start to fail in a stressed environment. I would suggest using the Sysinternals' testlimit tool to stress the entire machine.

Priapism answered 31/7, 2011 at 21:37 Comment(1)
If your in linux there's a program called cpulimit limit speed by process - I'm not familiar with ulimit but maybe this could make life easierSheryl
M
0

See https://serverfault.com/questions/36309/throttle-down-cpu-speed-of-vmware-image were it is claimed free-as-in-beer VMware vSphere Hypervisor™ (ESXi) allows you to select the virtual CPU speed on top of setting the memory size of the virtual machine.

Malchus answered 1/8, 2011 at 12:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.