CPU and Memory Cap for an AppDomain

耗尽温柔 提交于 2019-12-18 05:39:26

问题


I want to host an exe in an appdomain and assign a CPU and Memory cap to it so that it does not use more than the assigned processing power. Is this possible to do and how?


回答1:


You can't cap the maximum memory directly, as far as I know.

However, from .NET 4 on, the memory currently allocated by an AppDomain is available in the AppDomain.MonitoringSurvivedMemorySize property if AppDomain.MonitoringIsEnabled is set to true. You can spin up a watchdog thread to monitor allocations.




回答2:


Looks like there is a solution for this requirement in .NET 4.0

http://www.c-sharpcorner.com/UploadFile/hasansheik/diagnostic-and-performance-monitoring-in-dotnet-4-0/




回答3:


Even the Windows performance monitors don't allow you to view CPU usage by AppDomain - since AppDomains are logical constructs of the CLR and are not known by the OS the only CPU usage tracking is at process level - I would be shocked if there is a way to limit something that you can't even monitor.

What exactly is your reason for wanting to do this? Why wouldn't you want your application to use all resources available to it? If it is simply a case of making sure there is enough overhead for other processes to run can't you just set the priority of the threads very low and let the Windows scheduler figure it out?




回答4:


The only way I know to do something like this is using HyperV (or similar products) and partitioning your applications into different virtual machines. But that's not exactly a cheap or simple solution.



来源:https://stackoverflow.com/questions/3717370/cpu-and-memory-cap-for-an-appdomain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!