From: Robert Klemme Date: 2011-10-22T00:49:05+09:00 Subject: Re: Creating threads can be slow? 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 -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/