-
Strategy for great number of threads to be scheduled (6 messages)
- Posted by: Jacky Hung
- Posted on: March 14 2007 05:56 EDT
hi , buddy, i need ur guys expertise. Lets say, we have a website, which provides each registered user one thread. with this thread, it runs every 5 seconds(do something , like 1+1)(the task can definitely be done within 5 seconds). If I really design the architecture of generating one thread for each user... i think it will suffer, and actually the os can not support so many concurrent threads ,say over 1000000 . So...could u give me some advice on it. or some good arrangement strategy on how to schedule each user to run the task once in 5 seconds. any reply is appreciated! thxThreaded Messages (6)
- Re: Strategy for great number of threads to be scheduled by Shiv Natarajan on March 15 2007 04:03 EDT
- Re: Strategy for great number of threads to be scheduled by Jacky Hung on March 15 2007 23:34 EDT
- Re: Strategy for great number of threads to be scheduled by Cameron Purdy on March 21 2007 03:51 EDT
- Re: Strategy for great number of threads to be scheduled by Jacky Hung on March 15 2007 23:34 EDT
- Re: Strategy for great number of threads to be scheduled by Christopher Stach II on March 15 2007 14:36 EDT
- Multiplexing by Ivor Bosloper on April 04 2007 13:56 EDT
- Re: Strategy for great number of threads to be scheduled by ape ape on July 06 2007 00:12 EDT
-
Re: Strategy for great number of threads to be scheduled[ Go to top ]
- Posted by: Shiv Natarajan
- Posted on: March 15 2007 04:03 EDT
- in response to Jacky Hung
Consider using a thread pool (refer java.util.concurrent package). I recommend using cached thread pool because threads can be lazily initialized. The only disadvantage with thread pool (as opposed to starting a new thread everytime) is that, once all the threads in the pool are created, they will be running all the time (waiting for a task to be submitted when idle). Each thread is a system resource and so the disadvantage. If you create a thread on need basis, the system resource will be freed after the job is done. -
Re: Strategy for great number of threads to be scheduled[ Go to top ]
- Posted by: Jacky Hung
- Posted on: March 15 2007 23:34 EDT
- in response to Shiv Natarajan
thank u guys,first. the requirement is each user's task should be done every 5s as precisely as possible. we can use thread pool to control the amount number of threads..but who can take care of each user's timer? should there be a thread per each user(or one thread for all users) to fetch the available thread from the pool? let me think it over: 1)one thread for detecting all users, when timeis up, go to the pool get the thread to do the task? 2)one thread per user for detecting, this is bad design...! 3)one detecting thread for certain number of users any other suggestions? -
Re: Strategy for great number of threads to be scheduled[ Go to top ]
- Posted by: Cameron Purdy
- Posted on: March 21 2007 15:51 EDT
- in response to Jacky Hung
the requirement is each user's task should be done every 5s as precisely as possible.
Then use a thread pool with at least as many threads as there are CPUs/cores. If the processing involves I/O, increase the number of threads until you bottleneck on the I/O or until the CPU utilization goes to 100%. You will not be able to spin up one thread for each user. That architecture cannot work, because you cannot have an infinite number of threads. Furthermore, after a certain number of threads, your throughput will _decrease_ because of the cost of thread scheduling and management.we can use thread pool to control the amount number of threads..but who can take care of each user's timer?
Your question is answered by the documentation for the concurrent package. Peace, Cameron Purdy Tangosol Coherence: The Java Data Grid -
Re: Strategy for great number of threads to be scheduled[ Go to top ]
- Posted by: Christopher Stach II
- Posted on: March 15 2007 14:36 EDT
- in response to Jacky Hung
Bad design. Why not use a thread pool to constantly process "expired" (last process time >= 5s ago) user data? Partition the chunks of users across threads, and then across machines, until you reach your performance requirements. -
Multiplexing[ Go to top ]
- Posted by: Ivor Bosloper
- Posted on: April 04 2007 13:56 EDT
- in response to Jacky Hung
Hi, Over 1000000 concurrent threads? You should definitely consider a multiplexing approach. Googling on "java threads multiplexing servlet" lead me to the following article; http://www-128.ibm.com/developerworks/library/j-nioserver/ The article and referenced resources will tell you what multiplexing is, how you can do it in Java, and how to combine it with Servlets. Good luck, Ivor -
Re: Strategy for great number of threads to be scheduled[ Go to top ]
- Posted by: ape ape
- Posted on: July 06 2007 00:12 EDT
- in response to Jacky Hung
Interesting design problem. What did you ultimately choose? How did it scale?