-
Notifications
You must be signed in to change notification settings - Fork 417
Thread Pool Updates #255
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
Merged
Merged
Thread Pool Updates #255
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
146e688
Consistent at_exit behavior for Java and Ruby thread pools.
jdantonio ab62410
Added a :stop_on_exit option to the enable_at_exit_handler function.
jdantonio f955955
Updated thread pool docs to better explain shutting down thread pools.
jdantonio 49158fe
Fixed calls to enable_at_exit_handler! that were missing opts.
jdantonio 7575f0a
Added missing 'it_should_behave_like :thread_pool' specs.
jdantonio 360bb22
Simpler :executor option syntax.
jdantonio 7218017
Updated method calls to use new 'executor: :immediate' syntax.
jdantonio 316b379
Updated default executors and associated documentation.
jdantonio 1011fcc
Added Executor#auto_terminate? predicate method.
jdantonio 3441a91
Added at_exit handler to TimerSet.
jdantonio 60d78a5
Simplified auto-termination of the global thread pools.
jdantonio 5fac5a7
Updated CHANGELOG.
jdantonio 67ce971
Simpler :executor option syntax.
jdantonio 2f1f1e7
Updated default executors and associated documentation.
jdantonio 8075149
Major refactor of global thread pools.
jdantonio 4d0bfe7
Updated specs from 'task pool' to 'fast executor'
jdantonio 5956014
Updated specs from 'operation pool' to 'io executor'
jdantonio 6b5ad7d
Fixed io/task vs. fast/operation executor mixup.
jdantonio a872a69
All high-level abstractions default to the global io executor.
jdantonio 7505bdb
Refactor, cleanup, document.
jdantonio 80faafa
Added shutdown/kill/wait_for_termination variants for global executors
jdantonio d43f093
Fixed bug in Actor causing it to prematurely warm global thread pools…
jdantonio 09475b4
Renamed private internal OptionsParser to ExecutorOptions.
jdantonio 550592d
Added Lazy, a simpler and faster variation of Delay.
jdantonio 664234b
Updated top-level requires
jdantonio 390ac66
Renamed Lazy to LazyReference.
jdantonio 1447a38
Updated Actor to use the global io executor.
jdantonio 1238a28
Moved actor stress test from spec to script in examples.
jdantonio 79de972
Replaced remaining references to global task and operation thread pools.
jdantonio 6d2f821
Updated travis config.
jdantonio 42d7646
Added 'nuclear option' Concurrent.disable_auto_termination_of_all_exe…
jdantonio 7763f11
Improved global config cleanup during testing.
jdantonio b254942
Moved global logger out of Configuration object.
jdantonio 09df063
Thread pool at_exit stores id and gets from ObjectSpace when not
jdantonio c1944a1
Updated CHANGELOG
jdantonio d07ff0b
Updated to latest version of all dev/test gems.
jdantonio 350dffe
Updated docs for LazyRegister.
jdantonio 8c77ef8
Rebased master after merging PR #258.
jdantonio e8c6f8a
Removed unnecessary and unsafe queue clearing in TimerSet.kill
jdantonio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| #!/usr/bin/env ruby | ||
|
|
||
| $: << File.expand_path('../../lib', __FILE__) | ||
|
|
||
| require 'benchmark' | ||
| require 'optparse' | ||
| require 'thread' | ||
| require 'rspec/expectations' | ||
|
|
||
| require 'concurrent/actor' | ||
|
|
||
| class ActorStressTester | ||
| include ::RSpec::Matchers | ||
|
|
||
| TESTS_PER_RUN = 5 | ||
| THREADS_PER_TEST = 10 | ||
| LOOPS_PER_THREAD = 25 | ||
|
|
||
| class Ping < Concurrent::Actor::Context | ||
| def initialize(queue) | ||
| @queue = queue | ||
| end | ||
|
|
||
| def on_message(message) | ||
| case message | ||
| when :child | ||
| Concurrent::Actor::Utils::AdHoc.spawn(:pong, @queue) do |queue| | ||
| -> m { queue << m } | ||
| end | ||
| else | ||
| @queue << message | ||
| message | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def initialize(opts = {}) | ||
| @tests = opts.fetch(:tests, TESTS_PER_RUN) | ||
| @threads = opts.fetch(:threads, THREADS_PER_TEST) | ||
| @loops = opts.fetch(:loops, LOOPS_PER_THREAD) | ||
| end | ||
|
|
||
| def run | ||
| plural = ->(number){ number == 1 ? '' : 's' } | ||
|
|
||
| puts "Running #{@tests} test#{plural.call(@tests)} " + | ||
| "with #{@threads} thread#{plural.call(@threads)} each " + | ||
| "and #{@loops} loop#{plural.call(@loops)} per thread..." | ||
|
|
||
| Benchmark.bm do |bm| | ||
| @tests.times do | ||
| bm.report do | ||
| test(@threads, @loops) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def test(threads, loops) | ||
| (1..threads).collect do | ||
| Thread.new do | ||
| loops.times do | ||
|
|
||
| queue = Queue.new | ||
| actor = Ping.spawn(:ping, queue) | ||
|
|
||
| core = Concurrent::Actor.root.send(:core) | ||
| children = core.instance_variable_get(:@children) | ||
| expect(children).to include(actor) | ||
|
|
||
| actor << 'a' << 1 | ||
| expect(queue.pop).to eq 'a' | ||
| expect(actor.ask(2).value).to eq 2 | ||
|
|
||
| expect(actor.parent).to eq Concurrent::Actor.root | ||
| expect(Concurrent::Actor.root.path).to eq '/' | ||
| expect(actor.path).to eq '/ping' | ||
|
|
||
| child = actor.ask(:child).value | ||
| expect(child.path).to eq '/ping/pong' | ||
|
|
||
| queue.clear | ||
| child.ask(3) | ||
| expect(queue.pop).to eq 3 | ||
|
|
||
| actor << :terminate! | ||
| expect(actor.ask(:blow_up).wait).to be_rejected | ||
| terminate_actors(actor, child) | ||
| end | ||
| end | ||
| end.each(&:join) | ||
| end | ||
|
|
||
| def terminate_actors(*actors) | ||
| actors.each do |actor| | ||
| unless actor.ask!(:terminated?) | ||
| actor.ask!(:terminate!) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # def trace! | ||
| # set_trace_func proc { |event, file, line, id, binding, classname| | ||
| # # thread = eval('Thread.current', binding).object_id.to_s(16) | ||
| # printf "%8s %20s %20s %s %s:%-2d\n", event, id, classname, nil, file, line | ||
| # } | ||
| # yield | ||
| # ensure | ||
| # set_trace_func nil | ||
| # end | ||
|
|
||
| if $0 == __FILE__ | ||
|
|
||
| options = {} | ||
|
|
||
| OptionParser.new do |opts| | ||
| opts.banner = "Usage: #{File.basename(__FILE__)} [options]" | ||
|
|
||
| opts.on("--tests=TESTS", "Number of tests per run") do |value| | ||
| options[:tests] = value.to_i | ||
| end | ||
|
|
||
| opts.on("--threads=THREADS", "Number of threads per test") do |value| | ||
| options[:threads] = value.to_i | ||
| end | ||
|
|
||
| opts.on("--loops=LOOPS", "Number of loops per thread") do |value| | ||
| options[:loops] = value.to_i | ||
| end | ||
|
|
||
| opts.on("-h", "--help", "Prints this help") do | ||
| puts opts | ||
| exit | ||
| end | ||
| end.parse! | ||
|
|
||
| ActorStressTester.new(options).run | ||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/usr/bin/env ruby | ||
|
|
||
| $: << File.expand_path('../../lib', __FILE__) | ||
|
|
||
| require 'benchmark' | ||
|
|
||
| require 'concurrent/delay' | ||
| require 'concurrent/lazy_reference' | ||
|
|
||
| n = 500_000 | ||
|
|
||
| delay = Concurrent::Delay.new{ nil } | ||
| lazy = Concurrent::LazyReference.new{ nil } | ||
|
|
||
| delay.value | ||
| lazy.value | ||
|
|
||
| Benchmark.bm do |x| | ||
| puts 'Benchmarking Delay...' | ||
| x.report { n.times{ delay.value } } | ||
| puts 'Benchmarking Lazy...' | ||
| x.report { n.times{ lazy.value } } | ||
| end |
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
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
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
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
Oops, something went wrong.
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.
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.
I think the
--format documentationwas there to see the last test where it was hanging. Is there another way?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.
I'm not sure if there's another way, but
--format documentationhas been in .travis.yml since June of last year. I only removed it a couple of weeks ago--then immediately added it back when we had a hanging test. I think we should keep it for now. Once we stabilize our tests we can remove it, but the full output is pretty valuable right now.