Repository navigation
Conversation
On JRuby, scheduled_task_count and completed_task_count come from Java's ThreadPoolExecutor#getTaskCount and #getCompletedTaskCount, which Java documents as approximate. A task handed to an idle worker that has not started it yet is in neither count, so the two can be equal while that task is still pending. RubyThreadPoolExecutor counts a task when it is posted, so the counts are exact there. Say this in the shared macros, which are used for ThreadPoolExecutor and the pools built on it. Fixes ruby-concurrency#1121
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1121.
I started from #1121 and checked it against the code. On JRuby,
JavaThreadPoolExecutor#scheduled_task_countand#completed_task_countreturn Java'sThreadPoolExecutor#getTaskCountand#getCompletedTaskCount, which the Java docs call approximate.RubyThreadPoolExecutorincrements its own counters under its lock when a task is posted and when it finishes, so on CRuby the counts are exact. The docs of both methods don't mention the difference.This PR takes the docs option from the issue. It adds a note to the
thread_pool_executor_attr_reader_scheduled_task_countandthread_pool_executor_attr_reader_completed_task_countmacros infixed_thread_pool.rb. These macros are used by both executors and by the attribute list ofThreadPoolExecutor, so the note shows up there and on the pools that inherit from it. The note says that on JRuby a task that was just posted can be missing from both counts, so the two can be equal before that task has run.JavaThreadPoolExecutoritself is@!visibility private, so I did not put the note there.The other option from the issue, counting posted and finished tasks in
JavaThreadPoolExecutorasRubyThreadPoolExecutordoes, changes the post path and has to agree with the Ruby executor on rejected and caller-run tasks. I left that choice to you.How I found it
I followed
scheduled_task_countandcompleted_task_countfrom theThreadPoolExecutordocs to both implementations and compared them. Then I ran the script from the issue against concurrent-ruby 1.3.8:lib/from master: 0/1000.Where this can show up in practice
Code that waits for a pool to become idle by checking
completed_task_count == scheduled_task_count, for example in test helpers. On JRuby that check can pass while a task that was just posted is still pending, as the issue describes for the Action Cable tests in Rails. With the note, the docs no longer suggest that the two counts are exact on every platform. This is my estimate beyond the report in #1121.Testing
yard doc --markup markdownonlib/concurrent-ruby/**/*.rb: the new text appears in thescheduled_task_countandcompleted_task_countentries ofConcurrent::ThreadPoolExecutor.ruby -con the changed file.bundle exec rakeand the specs (comment-only change), andrake yardwith the project template.