简体   繁体   English

有没有办法限制进程的CPU /内存?

[英]Is there any way of throttling CPU/Memory of a process?

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 ). 我可以使用Fiddler模​​拟一个慢速网络( http://www.fiddler2.com/fiddler2/ )我可以看一下使用Process Explorer的流程如何使用CPU( 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? 有什么方法可以限制进程可以拥有的CPU数量,或者进程可以拥有多少内存来更有效地模拟用户计算机? (In order to isolate performance problems for instance) (例如,为了隔离性能问题)

I suppose I could use a VM, but I'm looking for something a bit lighter. 我想我可以使用VM,但我正在寻找更轻松的东西。

I'm using Windows XP, but a solution for any Windows machine would be welcome. 我正在使用Windows XP,但欢迎任何Windows机器的解决方案。 Thanks. 谢谢。

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.) 平台SDK过去常常带有压力工具,可以在过去的日子里做到这一点(SDK中的STRESS.EXECPUSTRESS.EXE ),但它们可能仍然存在(请检查您的平台SDK和/或Visual Studio安装这两个文件 - 遗憾的是我已经在我正在打字的机器上安装了PSDK和VS.)

Other tools: 其他工具:

  • memory : performance & reliability (eg handling failed memory allocation): can use EatMem 内存 :性能和可靠性(例如处理失败的内存分配):可以使用EatMem
  • CPU : performance & reliability (eg race conditions): can use CPU Burn , Prime95 , etc CPU :性能和可靠性(例如竞争条件):可以使用CPU BurnPrime95
  • handles (GDI, User): reliability (eg handling failed GDI resource allocation): ??? 句柄 (GDI,User):可靠性(例如处理失败的GDI资源分配):??? 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 可能必须编写自己的,但用完GDI句柄(有缺陷的GTK应用程序通常会把它们全部吃掉,直到系统上的所有其他应用程序像苍蝇一样开始死机)是对任何Windows应用程序的真正测试
  • disk : performance & reliability (eg handling disk full): DiskFiller , etc. 磁盘 :性能和可靠性(例如处理磁盘已满): DiskFiller

AppVerifier has a low-resource simulation feature. AppVerifier具有低资源模拟功能。

You could also try setting the priority of your process to be very low. 您还可以尝试将流程的优先级设置得非常低。

您可以运行MemAlloc来咀嚼RAM,可能会一次打印几份

I found a related question: 我找到了一个相关的问题:

Set Windows process (or user) memory limit 设置Windows进程(或用户)内存限制

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. 该问题的接受答案有一个指向Windows API的SetProcessWorkingSetSize的链接,因此它不是一个可以限制进程可以使用的内存量的工具。

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. 在更改进程可以使用的CPU资源量方面,如果您不介意每个核心限制资源的粒度,任务管理器可以更改进程的处理器关联。

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. 如果开发计算机具有多个核心但用户计算机只有一个核心,那么,不是允许进程在所有可用核心上运行,而是将进程的处理器关联性设置为仅一个核心。

It has nothing to do with SetProcessWorkingSetSize 它与SetProcessWorkingSetSize无关

Just use internal Win32 kernel apis to restrict CPU Usage 只需使用内部Win32内核apis来限制CPU使用率

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM