-
Notifications
You must be signed in to change notification settings - Fork 419
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
Create method ThreadPoolExecutor#active_count to expose the number of threads that are actively executing tasks #1002
Conversation
3919c53
to
9a4fbcb
Compare
9a4fbcb
to
d9bf21d
Compare
@@ -73,6 +73,11 @@ def completed_task_count | |||
@executor.getCompletedTaskCount | |||
end | |||
|
|||
# @!macro thread_pool_executor_attr_reader_available_worker_count | |||
def available_worker_count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, should this just be available_count
or is the worker_count
taxonomy established here/elsewhere?
5.times do
Thread.new do
if pool.available_worker_count > 0 # query
pool << proc {...} # use
end
end
end This PR encourages time-of-check / time-of-use race conditions. While I see the value of this interface/method, I don't think it solves the original problem. Given that Alternatively, if we think that is a terrible idea (consistency
|
I'm OK to add this as a monitoring method, and of course yeah it's always potentially stale info, as for other monitoring methods. It doesn't address #684 though, we'd probably need to fix the ThreadPoolExecutor to handle having a not-unlimited queue. |
@eregon What do you think of using |
oh! I think I understand this queuing thing better. The concurrent-ruby/lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb Lines 117 to 125 in 9f40827
...though confusingly it must be combined with I don't object if we wanted to say |
d9bf21d
to
06b5bfb
Compare
… threads that are actively executing tasks
06b5bfb
to
5d286b6
Compare
Connects to #684.
I called it "available" becauseready
means the thread has already been created but is idle, which isn't inclusive of uncreated workers that could still be added to the pool.This exposes the equivalent of the Java ThreadPoolExecutor's
getActiveCount
: "Returns the approximate number of threads that are actively executing tasks."