-
Notifications
You must be signed in to change notification settings - Fork 419
Global thread pool is now a thread pool executor. #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Perhaps an at_exit hook can solve the JRuby issue. I'll have to experiment with that. |
This latest update seems to solve the shutdown problem I was experiencing on JRuby. |
There's one thing about architecture I'd like to talk about: the global thread pool. Do you think this could be a good improvement? |
@mighe I think that's a great idea. I think it makes sense for some of the abstractions, but I think some would need the executor set on construction, not task execution. For Concurrent::Future.execute(executor: executor) do
# long running operation
end Some of the other abstractions (like agent = Concurrent::Agent.new(executor: executor) If we take this approach then we can get rid of the For now I've added a second global thread pool. One for short-running tasks and another for long-running operations. And I've exposed those thread pools through module functions so they can be post to directly: Concurrent::task do
# short running task
end
Concurrent::operation do
# long running operation
end I've also updated short = Concurrent::Future.execute{ :foo }
short = Concurrent::Future.execute(task: true){ :foo }
short = Concurrent::Future.execute(operation: false){ :foo }
long = Concurrent::Future(task: false){ :bar }
long = Concurrent::Future(operation: true){ :bar } This should allow for easy distinction between short-running and long-running tasks without the individual programmer needing to create their own thread pools. Thoughts? |
@mighe The latest commit on this PR adds the Does this work for what you suggested? @chrisseaton The latest commit makes a small change to |
Yes, this is exactly what I thought! |
Global thread pool is now a thread pool executor.
@mighe @chrisseaton @lucasallan
In this PR I've made the global thread pool a
ThreadPoolExecutor
instance. Before this commit it wasn't a real thread pool. It was aPerThreadExecutor
(formerlyNullThreadPool
) which spawned a new thread for every request. I'd like to discuss if this is the best direction for this gem. There are two issues to discuss:kill
it. Is there a way to prevent this? If not, we may have to default to a Ruby thread pool even when running under JRuby.I've added a demo program at
demos/global_thread_pool-demo.rb
that creates 500Future
objects each of which makes a call to a RESTful API. It outputs the time it takes to perform the task both sequentially and concurrently.