Is there any way of throttling CPU/Memory of a process?
Asked Answered
E

6

14

Problem: I have a developers machine (read: fast, lots of memory), but the user has a users machine (read: slow, not very much memory).

I can simulate a slow network using Fiddler (http://www.fiddler2.com/fiddler2/) I can look at how CPU is used over time for a process using Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx).

Is there any way I can restrict the amount of CPU a process can have, or the amount of memory a process can have in order to simulate a users machine more effectively? (In order to isolate performance problems for instance)

I suppose I could use a VM, but I'm looking for something a bit lighter.

I'm using Windows XP, but a solution for any Windows machine would be welcome. Thanks.

Emit answered 27/2, 2009 at 6:46 Comment(0)
L
5

The platform SDK used to come with stress tools for doing just this back in the good old days (STRESS.EXE, CPUSTRESS.EXE in the SDK), but they might still be there (check your platform SDK and/or Visual Studio installation for these two files -- unfortunately I have niether the PSDK nor VS installed on the machine I'm typing from.)

Other tools:

  • memory: performance & reliability (e.g. handling failed memory allocation): can use EatMem
  • CPU: performance & reliability (e.g. race conditions): can use CPU Burn, Prime95, etc
  • handles (GDI, User): reliability (e.g. handling failed GDI resource allocation): ??? may have to write your own, but running out of GDI handles (buggy GTK apps would usually eat them all away until all other apps on the system would start falling dead like flies) is a real test for any Windows app
  • disk: performance & reliability (e.g. handling disk full): DiskFiller, etc.
Leges answered 27/2, 2009 at 6:53 Comment(1)
I've tried CPU burn, it seems to work well. It is a bit like a sledgehammer though. I haven't tried the eatmem though. Marked as the accepted answer.Emit
H
3

AppVerifier has a low-resource simulation feature.

You could also try setting the priority of your process to be very low.

Hartsock answered 27/2, 2009 at 8:18 Comment(0)
A
1

You can run MemAlloc to chew up RAM, possibly a few copies at once.

Autotype answered 27/2, 2009 at 6:54 Comment(0)
I
1

I found a related question:

Set Windows process (or user) memory limit

The accepted answer for the question has a link to the Windows API's SetProcessWorkingSetSize, so it's not exactly a tool that can limit the amount of memory that a process can use.

In terms of changing the amount of CPU resources a process can use, if you don't mind the granularity of per-core limiting of resources, Task Manager can change the processor affinity of a process.

In Task Manager, right-click a process and select "Set Affinity...", then select the processor cores that the process can be assigned to.

If the development machine has many cores but the user machine only has one, then, rather than allowing the process to run on all the available cores, set the process' processor affinity to only one core.

Illogic answered 27/2, 2009 at 6:58 Comment(0)
B
0

It has nothing to do with SetProcessWorkingSetSize

Just use internal Win32 kernel apis to restrict CPU Usage

Bela answered 27/2, 2009 at 11:19 Comment(1)
What apis do provide the option to restrict CPU usage?Stenography
T
0

For CPU throttling, take a look at Battle Encoder Shirase (BES). It was developed for throttling a game which maxed out the CPU, but I've used it to throttle a crypto miner background task. I've used version 1.6.3 for a few years, seems pretty solid.

Tiphany answered 18/3, 2023 at 7:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.