Is it possible to force an existing Java application to use no more than x cores?

后端 未结 2 1584
渐次进展
渐次进展 2020-12-01 07:37

We are benchmarking existing Java programs. They are threaded applications designed to benefit from multi-core CPUs. We would like to measure the effect of the number of cor

2条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 08:21

    Turn the problem upside down; instead of figuring out how to restrict the application to only use n cores on an m core machine, figure out how to make sure there are only n cores available to your application. You could write a very simple program that eats up one core by doing something like while (true); and start m-n instances of that program running at the highest priority, thus ensuring that your code only has n cores available.

    Alternatively, if your BIOS or OS allows disabling CPU cores, that works out too. I know CHUD tools on Mac OS X used to do it, but I haven't touched those tools since the G5 era, so that might not work anymore.

提交回复
热议问题