From: Christian Pedaschus Date: 2011-10-22T01:25:05+09:00 Subject: Re: Creating threads can be slow? On 10/21/2011 05:49 PM, Robert Klemme wrote: > On Fri, Oct 21, 2011 at 5:41 PM, wam r. wrote: >> I am currently load testing a system. Under load, the couple of lines >> below where I am creating threads are becoming slow: > Well, under load anything is slow, isn't it? :-) > >> temp = [] >> foo_array.each do |foo| >> temp << Thread.new (foo) { |e| ...} >> end > Btw, you can simplify that to > > temp = foo_array.map {|foo| Thread.new(foo) {|e| ...}} > >> I have put a "timer" around these few lines. I know it is completely >> dependent on the system but just to give an idea it can take more than >> 20s for <> 100 threads. Just the code above. I am using 1.8.7 and the >> standard MRI. >> >> Am I missing something? Do threads involve a significant overhead? > Generally, i.e. in many common programming languages, creating threads > is quite an expensive operation (compared to a method call for > example) because of the overhead involved (allocating the stack and > other things which need to be done). Having said that you might want > to try 1.9* versions of Ruby which are generally faster than 1.8*. > > Kind regards > > robert > And just in case Ruby 1.9* is not an option, you may want to try Ruby Enterprise Edition which "could" be faster than MRI (untested guess, but i had cases where it produced significant speedups so it may be worth a try). http://www.rubyenterpriseedition.com/ Greets, Chris