On Tue, Nov 17, 2009 at 1:07 PM, jhaagmans <[email protected]> wrote:
> > Hi, > > I have a backgroundrb worker that gets triggered every second. When > it's triggered, it's supposed to make 2 - 15 http-requests using > Net::HTTP. My idea was to put every execution into a thread so the > next execution doesn't have to wait for the last one. So basically: > > def http_requests > hosts.each do |host| > Thread.new do > begin > client = Net::HTTP.start(host) > rescue > #store host as inactive > ensure > client.finish if client.active? > end > end > end > end > > Of course that's not all it does, but I hope you understand what I'm > trying to do here. > > The thing is: this doesn't get done once a second. It appears that > every HTTP-request is waiting for the last one to complete, which > clots up Rails very fast! > > My question is: why is this? Does this have anything to do with Ruby > not being threadsafe (I doubt it, because that just means threads > aren't executed as precisely as with jRuby, right?) or is Net::HTTP > not able to make requests while another Net::HTTP request is still > running? And what to do? > > I hope you can help. > The Global Interpreter Lock (GIL) prevents threads from executing in parallel when using Ruby 1.8.6 aka MRI, 1.8.7, and 1.9.1 aka YARV. However, JRuby 1.3.x/1.4.x, MacRuby 0.5 Beta 2, Maglev and several other upcoming Ruby VMs are not constrained by the GIL. Thus, they can execute threads in parallel. Good luck, -Conrad > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<rubyonrails-talk%[email protected]> > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en > -~----------~----~----~----~------~----~------~--~--- > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.

