I've read several Questions and articles regarding how to decide on a size for a thread pool. Questions include:
- How to choose thread pool size?
- What is the relationship between number of CPU cores and number of threads in an app in java?
- Java thread pool size (Executors)
Articles include:
However, none of these directly address the issue of Hyper-Threading on Intel chips.
On a computer with Hyper-Threading enabled, should I consider the virtual cores when deciding thread pool size?
Take for example Brian Goetz’ advice in the Java Concurrency In Practice book that, generally speaking, for a CPU-bound app one might consider using ( # of cores + 1 )
as the number of threads. For an Intel Core i7 chip with 4 real cores and 8 virtual (Hyper-Threading) cores, would that formula be ( 4 + 1 )
or ( 8 + 1 )
?
Also, how much of difference does the nature of the app matter in how to consider the Hyper-Threading cores?
Contrary to the mention above, my own app is not CPU bound. Instead my app is a server-side Vaadin app where the threads are making Internet connections and hitting a local database through JDBC, several times a minute. Given that Hyper-Threading is basically a second set of registers attached to the same core, perhaps a CPU-bound app should consider only real cores while a network/IO-bound app should consider virtual cores?
Lastly, does the type of Intel chip affect Hyper-Threading and therefore the calculation of thread pool size? Specifically, is there a difference regarding this issue between a Xeon and a Core i7/i5? For example, the difference between a current MacBook (Core i7) and Mac Pro (Xeon).
I realize there are many variables involved, and this is a complex topic. No perfectly precise answers are possible. I'm just looking for some general rules and advice to help out programmers like me who are not as savvy about such hardware matters.