B
bob smith
I'm looking at this method in the Executors class:
How much is too much in terms of me telling it how many threads I want? Is it okay to ask for 100 threads? What about 256?
How much is too much in terms of me telling it how many threads I
want? Is it okay to ask for 100 threads? What about 256?
However, 100 to 300 threads is trivial for most modern system. Since
most tasks will be IO-bound, it make sense to have lots of threads so
some can be running while others wait for data to be returned. (Sorry
to contradict Mr. Meier but I'm pretty sure he's off base.) Given a
3000 is probably approaching some sort of upper limit on most "average"
servers. Don't neglect to measure actual running performance, but I
don't think commodity hardware can handle that many practically.
Joerg said:Obviously, you can pretty much have Integer.MAX_VALUE threads if all of
them are waiting without negatively impacting your waiting performance -
that's not really a sensible way to look at that question
I said, and stand by, that context switching is not free and is the cost of
having too many threads. Threads that sleep or otherwise wait, such as for
IO, don't typically cause much context switching.
That being said, I would expect the case of 100s of threads waiting for IO
probably an edge case (for use cases such as web servers), and the majority
of cases would have IO restricted to a small number of the threads. YMMV.
We once ran (by accident) something that triggered 100,000 threads (+ GC
and whatever) on a normal Linux server with a quad core CPU and it still
worked (although much slower than with the intended 100). As far as I know,
neither Linux nor the hardware was anything unusual.
How much is too much in terms of me telling it how many threads I want? Is=
it okay to ask for 100 threads? What about 256?
Just a cautionary, and that's not saying you're ignoring this aspect:I'm looking at this method in the Executors class:
--------------------------------
newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads)
Creates a thread pool that reuses a fixed set of threads operating off a shared unbounded queue. If any thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks.
--------------------------------
How much is too much in terms of me telling it how many threads I want? Is it okay to ask for 100 threads? What about 256?
Thanks.
While modern operating systems support thousands of threads, there are
really not many advantages in using more threads than you have CPUs/cores,
As you have read in the rest of this thread, the answer is "it depends".I'm looking at this method in the Executors class:
--------------------------------
newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads)
Creates a thread pool that reuses a fixed set of threads operating off a shared unbounded queue. If any thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks.
--------------------------------
How much is too much in terms of me telling it how many threads I want? Is it okay to ask for 100 threads? What about 256?
Thanks.
Obviously, you can pretty much have Integer.MAX_VALUE threads if all of
them are waiting without negatively impacting your waiting performance -
that's not really a sensible way to look at that question
Obviously.
I said, and stand by, that context switching is not free and is the cost of
having too many threads.
Threads that sleep or otherwise wait, such as for
IO, don't typically cause much context switching.
We once ran (by accident) something that triggered 100,000 threads (+ GC
and whatever) on a normal Linux server with a quad core CPU and it still
worked (although much slower than with the intended 100). As far as I know,
neither Linux nor the hardware was anything unusual.
I'm looking at this method in the Executors class:
--------------------------------
newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads)
Creates a thread pool that reuses a fixed set of threads operating off a shared unbounded queue. If any thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks.
While modern operating systems support thousands of threads, there are
really not many advantages in using more threads than you have CPUs/cores,
and the additional context switching of having more threads than cores
comes with its own performance cost.
Obviously, you can pretty much have Integer.MAX_VALUE threads if all of
them are waiting without negatively impacting your waiting performance -
that's not really a sensible way to look at that question
I said, and stand by, that context switching is not free and is the cost of
having too many threads. Threads that sleep or otherwise wait, such as for
IO, don't typically cause much context switching.
That being said, I would expect the case of 100s of threads waiting for IO
probably an edge case (for use cases such as web servers), and the majority
of cases would have IO restricted to a small number of the threads. YMMV.
The last time I looked, each thread ate up 1MB.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.