Path: csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: nThreads Date: Thu, 14 Feb 2013 22:19:26 +0100 Lines: 45 Message-ID: References: <1mv2pq2irp6wa$.1lqfljcyio53l$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net KbvRRjVGLDEPXq9Grnx5QAFwvlI6DlharVadTU4ftEl04ClBKhk7VSYH+PttgxrVQ= Cancel-Lock: sha1:vdAhssvQmAauUOD4WxgUnAYVAV8= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 In-Reply-To: <1mv2pq2irp6wa$.1lqfljcyio53l$.dlg@40tude.net> Xref: csiph.com comp.lang.java.programmer:22311 On 14.02.2013 01:46, Joerg Meier wrote: > On Wed, 13 Feb 2013 16:06:37 -0800, markspace wrote: > >> 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 > > 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. Nobody questioned that. > Threads that sleep or otherwise wait, such as for > IO, don't typically cause much context switching. Yes, but in a pool with a fixed upper limit of threads they consume a slot while sitting there doing nothing (and causing no CPU cost). In this case a core will be idle if you limit pool size to number of cores. If the application is doing IO (or anything else which might cause intermediate blocking) you are unnecessarily restricting throughput of the application if you take number of cores (or threads as they are called in some architectures) as limit. What the best limit is obviously depends on the nature of the application. > 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. There you go. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/