【发布时间】:2013-04-14 06:03:51
【问题描述】:
有什么区别-
newSingleThreadExecutor vs newFixedThreadPool(20)
从操作系统和编程的角度来看。
每当我使用 newSingleThreadExecutor 运行我的程序时,我的程序运行良好,端到端延迟(第 95 个百分位数)大约在 5ms 附近。
但是一旦我开始运行我的程序使用-
newFixedThreadPool(20)
我的程序性能下降,我开始看到端到端延迟为37ms。
所以现在我试图从架构的角度来理解线程数在这里意味着什么?以及如何确定我应该选择的最佳线程数是多少?
如果我使用更多的线程,会发生什么?
如果有人能用通俗的语言向我解释这些简单的事情,那对我来说将非常有用。感谢您的帮助。
我的机器配置规范-我正在从 Linux 机器上运行我的程序-
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 45
model name : Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
stepping : 7
cpu MHz : 2599.999
cache size : 20480 KB
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm arat pln pts
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 45
model name : Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
stepping : 7
cpu MHz : 2599.999
cache size : 20480 KB
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm arat pln pts
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
【问题讨论】:
-
您对这里的答案不满意吗:stackoverflow.com/questions/16125626/… ?
-
我想更详细地了解。我发布的那个问题更多的是关于编程和寻找瓶颈,但格雷认为这可能是线程大小的问题。所以我想让我们发布另一个问题,但这次更具体的是架构的观点。
标签: java multithreading concurrency cpu-cores processors