Skip to main content

Many, many threads running concurrently on a single CPU ...

11 replies [Last post]
jfelrod1960
Offline
Joined: 2003-11-01
Points: 0

I would like to know if anyone has had experience writing an application that may use as many as 20,000 threads running at once in an environment that utilizes only one CPU whether it is a single or dual core processor? What kind of performance problems have you experienced or is it a problem for JSE to handle?

Jeff

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jkleemann
Offline
Joined: 2004-06-29
Points: 0

Hi,

how about a try&buy option on a T2000 ? It can cope with that much threads, but i would suggest to switch to some more sophisticated method than just creating 20.000 threads.

alexlamsl
Offline
Joined: 2004-09-02
Points: 0

Not sure about the usefulness of the T1 systems in this case - there's only one float-point arithmetic unit on the whole chip even though it has 8 cores and stuff.

May be T2 systems would help, if they have come around in the future.

matrangolo
Offline
Joined: 2005-11-21
Points: 0

Hi,

I think that using threads is a very bad idea for your problem. I'm not a specialist in the simulation field but I know that massive simulation are implemented using discrete time algorithms with the use of message passing between the "actors" of the simulated system.

Try to google queue theory or discrete simulation.

My two cents,
Ugo.

jfelrod1960
Offline
Joined: 2003-11-01
Points: 0

Your point is well taken. Most Parallel GAs are executed on supercomputers that have multiple processors. I'm early in the development stage right now and so this massively threaded option may not be part of the final product.

I have done a few Parallel GA problems on a single processor system and was able to find a solution that a single-thread GA was not able to find. The performance was not that bad. The purpose of my GA engine is to find solutions to problems offline. Like using a GA to optimize a neural network for example. The neural network, once optimized, will run in a time-sensitive application.

I will do that search you suggested. Thanks!

> Hi,
>
> I think that using threads is a very bad idea for
> your problem. I'm not a specialist in the simulation
> field but I know that massive simulation are
> implemented using discrete time algorithms with the
> use of message passing between the "actors" of the
> simulated system.
>
> Try to google queue theory or discrete simulation.
>
> My two cents,
> Ugo.

billrobertson42_
Offline
Joined: 2006-02-19
Points: 0

Even running two threads to try to do a bunch of small tasks on a single CPU system can slow your program down unless those threads spend the majority of their time just waiting on IO.

A previous system that I wrote had a strategy for single threaded execution and another strategy for multi threaded execution, and after detecting the number of available CPU's I picked the appropriate strategy, and in the multi threaded cases, picked an appropriate number of threads to do the work.

Attempting to run in multi-threaded mode on a single cpu computer would slow the whole thing down by about 20%. Picking anything more than n+1 threads (where n=number of cpu's) in multi threaded mode was no good either.

briand
Offline
Joined: 2005-07-11
Points: 0

The question that comes to my mind is why? Why do you want/need so many threads on a 1 CPU system?

It seems to me that you could do better by having a few threads and use NIO selectors (assuming you are dealing with sockets, not files). That way, you can have a thread pool that handles incoming connections and service requests and you can size the thread pool based on the amount of computing resources available on the system.

One thing to consider is that threads are not really a light weight resource. Each thread has an associated thread stack and the more threads you instantiate, the more address space you consume, which generally forces you to have a smaller java heap. With large numbers of active threads, you generally need larger heaps to support those threads (though admittedly, this is really a bigger problem on large multi-processor systems, as more threads are concurrently active).

jfelrod1960
Offline
Joined: 2003-11-01
Points: 0

> The question that comes to my mind is why? Why do you
> want/need so many threads on a 1 CPU system?

I'm building a Genetic Algorithm Engine that will allow an AI programmer to build a parallel genetic algorithm (PGA) that has a very complex architecture. The PGA have sub-populations that run concurrently. In each sub-population the programmer can choose to generate a new population in parallel by having operations run concurrently within each sub-population thread.

I may not be able to add this feature so I decided to post the question here. Problems like these have been done on supercomputers, but I feel like by the time I have this product finished, 2007-2008? the multiple-core processors will be out in full force.

Thanks for the replies!

sdo
Offline
Joined: 2005-05-23
Points: 0

You're much better off using a ThreadPool model. You can create 20000 (or whatever) tasks and create a thread pool to run the tasks. Then the size of the thread pool can be adjusted to the platform you're running on.

That way, you won't have the issue of being able to create enough threads (with a typical stack size, you're limited to a few thousand). And you'll have much less problem with contention, since only a few threads can be contending for any resource at any one point in time.

Java SE 5 comes with an executor class (which is just a fancy thread pool). You can also write your own (which I'm supposed to say is not recommended, but I find the executors a little more difficult than necessary, and not necessarily as performant as simple thread pools).

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

I just can repeat what previous posters said, be very careful with that many threads.

> What kind of performance problems have you experienced
I didn't do this but if you plan all threads to be active (=in running state) you'll see:
- Very low throughput
- Tons of cache-misses (since each Thread has some memory associated with it which is used frequently (stack, ...). If you've that many threads you'll soon fill the cache.
- it OS-Limits on some operating systems.
I've heard that windows-nt/2k/xp is able to handle about 7000-10000 Threads more or less efficiently. Old Linux-Versions (2.4 and pre) completly suck, linux-2.6+ is an excellent performer.
- A lot of memory-waste. Each thread has "a lot" of memory associated.

lg Clemens

> or is it a problem for JSE to handle?

jfelrod1960
Offline
Joined: 2003-11-01
Points: 0

I appreciate everyone taking the time to answer my questions. Thanks! I will give you guys some results when I finish coding and testing this component. Thanks again!

alexlamsl
Offline
Joined: 2004-09-02
Points: 0

Yes I have for the stress tests for my class library.

The general problem, apart from stack overflow which limits the maximum number of threads you can sprawn, is the fact that any synchronised structures are really costly.