开发者

More cores VS more frequency for Java [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 6 years ago.

Improve this question

For heavily multi-threaded Java server app, what would be more recommended, having more CPU cores (6 instead of 4), or higher CPU frequency (2.53 Ghz instead of 2.4 Ghz).

It seems to me that i开发者_StackOverflow社区t obvious more cores is the way to go, but I would like to hear a second opinion.

Thanks.


Since you said "heavily multi-threaded", I'd say that more cores are preferred. Higher clock speeds will just mean faster context switching for threads. If your algorithms are parallelized, I'd say more cores will give you a greater boost.


If your application is currently CPU-bound, and if it is easy to increase the number of parallel threads that are doing computational work (i.e. there's minimal dependencies between them), then you will benefit from increasing the number of cores.

If neither of these is true (for instance, if most of your threads are for handling disk, network or user IO), you won't see much benefit either way.


If your application scales well, you can assume your processing power for comparison purposes is speed * cores when comparing machines of the same architecture.

Based on those assumptions, your throughput is likely to be proportional to

  • 4 * 2.53 = 10.12
  • 6 * 2.4 = 14.4

The 6 core system could have up to 40% higher throughput.

However for comparing CPU's of similar but not the same architecture I suggest you look at SPEC_int_rate or SPEC_fp_rate for your CPUs. (Only use the latter if its floating point intensive, if in doubt, its not ;)


It depends on the nature of the tasks. If the tasks are serial in nature ("task 1 must be accomplished before task 2, task 2 must be accomplished before task 3," etc.) then processor speed is going to win; if the tasks can be executed in parallel ("tasks 1, 2, and 3 do not use data between them, and task 4 collates the results") then core count is more important.

In other words, it depends entirely on what the processors are being used for.


2.53/2.4 = 1.05

6/4 = 1.5

If the threads are relatively independent of each other - which is definitely the case in a server app where there's just a bunch of threads in a pool, and each of them is given in the next request from client - then the answer is indeed obvious.


I also want to add that three more facotrs should be taken into account when doing a similar analysis.

  1. Is the task memory intensive? I/O intensive? Programs that spend a lot of their time waiting for memory/disk/network accesses to finish do not benefit from higher frequency since processors are not the bottleneck. They do however benefit from parallelism since more requests can be fired in parallel and some of the latency can be hidden.

  2. As someone already pointed out, take application scalability into account. If app only has 4 threads of concurrent execution, 6 cores won't help but higher freuqency may help.

  3. The amount of serial code (inherent or accidental due to contention for critical section or load imbalance) can mean that higher frequency is better than more cores. When running serial code, the speed of the single core running the single thread is more important. This is derived from Ahmdahl's law.

 Execution time with N cores = Time in Serial code  + (Time in parallel code as 1 thread/N)  

Now if parallel part is small already, then increasing N will only help a little. Say Time in parallel when run as 1 thread is 10s and time in serial part is 5s. 

With 1 core ,  15s. 
With 2 cores,  10s,   
With 4 cores,  7.5s,
With 5 cores,  7s
With 6 cores,  6.66s

Now instead, if we had 4 cores with 5% higher frequency, 

Total time will be 7.5/1.05 = 7.14s. Thusm 6 cores seem faster, clearly!

Note: I assumed frequency perfectly translates into performance but this is often not the case due to memory and i/o accesses but it was fine for this analysis.

By the way, one interesting side note: The reason your 6 cores look better is because the two configurations are not comparable as their electric/heating requirements (from a running cost stand point) are not the same. The 6-core will cost more to buy, more to run, more to cool, etc and hence it is likely to provide higher performance.

@Joonas: Server apps can have critical sections, e.g., MySQL is full of them that make threads effectively serial when they contend for the critical section.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜