On Fri, Oct 21, 2011 at 5:41 PM, wam r. <wamrewam / googlemail.com> 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 =3D []
> foo_array.each do |foo|
> =A0temp << Thread.new (foo) { |e| ...}
> end

Btw, you can simplify that to

temp =3D 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


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/