Closed zozo closed 8 years ago
I am not a celluloid member, but i have been using celluloid for a long time
And i have a gem which does almost what you need. You can take a look here: https://github.com/bogdanRada/celluloid_pubsub/blob/master/lib/celluloid_pubsub/web_server.rb
As you can see , i think you should first accept the conection in the server and then only detach the connection and send the request ( `connection.request
) to the ConnectionHandler ( Which should be renamed probably to RequestHandler)
It is bad idea to send the connection instance every time you receive a new request, because each of the ConnectionHandler instances will spawn new threads ( beacause of the async.run
where they will try each of them to handle same request.
Instead you should create those instances with the request that needs to be handled , avoiding in this case a deadlock, because right now they will try to use same resource.
Hope you understand my point.
@bogdanRada Thanks for you help. Seems like I didn't understand my problem correctly.
Before I had separate process listening different ports and load balancing with nginx, but now I need only one process to simplify integration with other system components. I found the way - create pool of RequestHandler actors and handle requests through this pool. This allow me to load all cores with one process, but performance of this solution is about two times slower. I'm keep digging and hope to find the way to have only one process and good performance.
That is not a reel problem, so I'm closing issue.
From what i know MRI <= 1.9 uses one core per process irrespective of number of threads spawned (due to GIL restrictions).
However Ruby 2.0 has support now for native threads and here are several improvements to Ruby garbage collector in ruby 2.2 as you can see from this post http://stackoverflow.com/questions/28308363/has-the-global-interpreter-lock-gil-been-removed-from-ruby-in-version-2-2 or from release notes https://github.com/ruby/ruby/blob/v2_2_0/NEWS
Also some other improvements have been made to threads in Ruby 2.3 https://github.com/ruby/ruby/blob/ruby_2_3/NEWS
There are though some considerations for Ruby 3 as far as i understood from this article https://medium.com/@franzejr/ruby-3-mri-and-gil-a302577c6634#.mrb1yvwev ( from 2015) to remove GIL .
But until Ruby 3 will be released , i think the best solution would be to use JRuby , which scales the work to use all cores automatically.
If you really need to use all cores then you might consider using JRuby but i am not sure if this is compatible with it. I honestly use JRuby on very rare ocassions.
I am glad though that i could help, if there is anything else that i can help with, let me know. Thanks a lot.
I'm trying to make reel application to load all available cores. But when I start basic example from the wiki and begin stress-test with ab, I'm getting:
That is my
test.rb
Gemfile:
ab output:
I've tested this on ubuntu 14.04.4 (under VirtualBox) and on OS X
Please, tell me the direction to dig into this problem.