Solaris上Java线程与CPU的良好比例是多少? [英] What is a good ratio of Java threads to CPUs on Solaris?

查看:178
本文介绍了Solaris上Java线程与CPU的良好比例是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个固定线程池为15的Java应用程序,该机器Solaris 10 SPARC有16个CPU。添加池大大提高了性能,但我想知道池中是否有太多线程。使用更少的线程可以提高性能,还是Solaris可以很好地完成线程调度。

I have a Java application that has a fixed thread pool of fifteen, the machine, Solaris 10 SPARC, has sixteen CPUs. Adding the pool has greatly increased performance, but I'm wondering if I have too many threads in the pool. Would performance be better with less threads or does Solaris do a good job of thread scheduling.

假设池大量使用15个CPU,那么其他应用程序线程需要各种CPU原因,并发垃圾收集就是一个很好的例子。现在,池和其他应用程序线程之间共享五个CPU。然后,一到七个CPU变为空闲,Solaris会将繁忙CPU上的线程共享时间移动到空闲CPU吗?

Say the pool is heavily using fifteen CPUs, then other application threads demand CPU for various reason, concurrent garbage collection is a good example. Now, five CPUs are shared between the pool and other application threads. Then CPUs one through seven become free, will Solaris move the threads sharing time on the busy CPUs to the free CPUs?

如果不是,保留池会更好吗?大小更小,以便其他应用程序线程总是有空闲的CPU?使问题更加复杂,应用程序中的CPU使用率非常零星。

If not, would it be better to keep the pool size smaller, so that there are always free CPUs for other application threads? Compounding the issue, CPU usage is very sporadic in the application.

推荐答案

如果您只执行cpu密集型任务(无IO) N + 1个线程(其中N是内核数量)将为您提供最佳的处理器利用率。

+1因为您可能出现页面错误,因此可能会因任何原因或等待而暂停同步期间的时间。

If you are doing only cpu intensive tasks (no IO) N+1 threads (where N is the number of cores) will give you the optimum processor utilization.
+1 because you can have a page fault, a therad can be paused to any reason or a small wait time during synchronization.

对于执行IO的线程,这不是很容易,你必须测试最佳大小。

这本书实践中的Java并发建议将此算法作为起点:

For Threads doing IO this is not really easy, you have to test the best size.
The book Java concurrency in practice suggests this algorithm as starting point:

N = number of CPUs
U = target CPU utilization (0 <= U <= 1)
W/C = ration of wait time to cpu time (measured through profiling)

threads = N * U * (1 + W/C)

IBM在其文章中使用相同的算法 Java理论与实践:线程池和工作队列,固定U = 1。
在IBM文章中也可以阅读N + 1事实,以提供两篇论文的来源。

IBM uses the same algorithm in their article Java theory and practice: Thread pools and work queues, with a fixed U=1. The N+1 fact can be read too in the IBM article, to provide origins for both theses.

这篇关于Solaris上Java线程与CPU的良好比例是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆