java Java限制资源使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10487840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java limiting resource usage
提问by rynojvr
Is there a way to limit both the number of cores that java uses?
有没有办法限制java使用的内核数量?
And in that same vein, is it possible to limit how much of that core is being used?
同样,是否有可能限制该核心的使用量?
采纳答案by Peter Lawrey
You can use taskset on linux. You can also lower the priority of a process, but unless the CPU(S) are busy, a process will get as much CPU as it can use.
您可以在 linux 上使用任务集。您还可以降低进程的优先级,但除非 CPU(S) 繁忙,否则进程将获得尽可能多的 CPU。
I have a library for dedicating thread to a core, called Java Thread Affinity, but it may have a different purpose to what you have in mind. Can you clarify why you want to do this?
我有一个将线程专用于核心的库,称为 Java Thread Affinity,但它的用途可能与您的想法不同。你能澄清你为什么要这样做吗?
回答by aleroot
I don't think that there are built-in JVM options to do these kind of tweaks, however you can limit CPU usage by setting priority and/or CPU affinity of the JVM process. If you are on Linux take a look at CPULimitthat is an awesome tool to do these kind of resource limitations.
我不认为有内置的 JVM 选项可以进行此类调整,但是您可以通过设置 JVM 进程的优先级和/或 CPU 关联性来限制 CPU 使用率。如果您在 Linux 上,请查看CPULimit,它是执行此类资源限制的绝佳工具。
回答by haosdent
https://github.com/haosdent/jcgroupjcgroup is your best choice. You could use this library to limit the CPU shares, Disk I/O speed, Network bandwidth and etc.
https://github.com/haosdent/jcgroupjcgroup 是你最好的选择。你可以使用这个库来限制 CPU 份额、磁盘 I/O 速度、网络带宽等。