From: khaines@... Date: 2007-08-26T04:15:07+09:00 Subject: Re: Thread safety techniques for server applications? On Sun, 26 Aug 2007, ara.t.howard wrote: >> I've heard that Ruby 2.0 won't use Green Threads, so hopefully this will >> change. I would assume the reason why Ruby uses Green Threads is to try and >> maintain portability over efficientcy. > > it's interesting to me that people assume green threads provide less > performance advantage that native threads. this is patently untrue: it all > depends on your task! to summarize > > - if your task is cpu intensive AND you are on an SMP box AND you use many > threads (aka lightweight processes) you will see a speed boost How do you figure that? On a CPU intensive task, the threading overhead just removes from the amount of time that the CPU has to work on the CPU intensive task. > - if your task is io/network bound and/or you are spawning a TON of threads > then green threads will provide a speedup on any decent (aka not windoze) > platform That's what I was saying. You have to have external latencies that you can capture without spending time blocking inside of an extension, and they have to represent a significant enough slice of the code's activities to overcome the overhead of thread creation, thread switching, and the additional cost of all of the extra objects that each thread and its contents imposes on the garbage collector. So I still maintain that most of the time, for most code, Ruby threads are not a vehicle for improved performance, and are best through of as a usefull tool for elegantly solving problems instead of as a tool to make stuff go faster. Kirk Haines