-
Notifications
You must be signed in to change notification settings - Fork 1.2k
S3 Executor support #3302
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
S3 Executor support #3302
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
8c7ca45
Add executor support
jterapin c21969a
Add changelog entry
jterapin 39ecf0a
Update TM with executor changes
jterapin a3f2b9f
Remove thread count support from MPU
jterapin 3156f7c
Update Object usage of executor
jterapin 84c9966
Add documentation/remove unused methods from DefaultExecutor
jterapin 8e16a3b
Add Default Executor specs
jterapin db1cb62
Update TM docs and impl
jterapin f907c3b
Update streaming MPU to use executor
jterapin 7cb940a
More MP Stream updates
jterapin 4003536
Update specs
jterapin 7dddda9
Update interfaces
jterapin 481f198
Update specs
jterapin 88bf44a
Update changelog
jterapin c1a25cd
Minor updates
jterapin 7522a16
Fix failing specs
jterapin 89cffe7
Merge branch 'version-3' into s3-executor-support
jterapin 9eea233
Feedback - address sleep in specs
jterapin 75b0d96
Feedback - update method name for cleanup_team_file
jterapin ad943ee
Feedback - wrap checksum callback
jterapin f1fc86a
Feedback - update method name in MPU
jterapin 09eae68
Feedback - streamline handling of progress callbacks
jterapin e824de0
Feedback - streamline docs
jterapin c073349
Merge branch 'version-3' into s3-executor-support
jterapin cd91eb7
Feedback - streamline opts
jterapin abf78d6
Feedback - remove sleep from specs when possible
jterapin 04a287f
Feedback - update to use 10 threads only
jterapin f7056a3
Merge branch 'version-3' into s3-executor-support
jterapin e921654
Using at_exit hooks for default executor
jterapin 78af1fd
Refine documentation
jterapin e5c8b32
Revert "Using at_exit hooks for default executor"
jterapin 163f1c4
Update docs
jterapin dce166e
Update changelog entry
jterapin 4b1efdd
Revert "Feedback - update to use 10 threads only"
jterapin 083d9a5
Update TM
jterapin b58b849
Add extra docs
jterapin 6214de8
Feedback - update shutdown method with mutex
jterapin 353da43
Update docs
jterapin 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# frozen_string_literal: true | ||
|
||
module Aws | ||
module S3 | ||
# @api private | ||
class DefaultExecutor | ||
DEFAULT_MAX_THREADS = 10 | ||
RUNNING = :running | ||
SHUTTING_DOWN = :shutting_down | ||
SHUTDOWN = :shutdown | ||
|
||
def initialize(options = {}) | ||
@max_threads = options[:max_threads] || DEFAULT_MAX_THREADS | ||
@state = RUNNING | ||
@queue = Queue.new | ||
@pool = [] | ||
@mutex = Mutex.new | ||
end | ||
|
||
# Submits a task for execution. | ||
# @param [Object] args Variable number of arguments to pass to the block | ||
# @param [Proc] block The block to be executed | ||
# @return [Boolean] Returns true if the task was submitted successfully | ||
def post(*args, &block) | ||
@mutex.synchronize do | ||
raise 'Executor has been shutdown and is no longer accepting tasks' unless @state == RUNNING | ||
|
||
@queue << [args, block] | ||
ensure_worker_available | ||
end | ||
true | ||
end | ||
|
||
# Immediately terminates all worker threads and clears pending tasks. | ||
# This is a forceful shutdown that doesn't wait for running tasks to complete. | ||
# | ||
# @return [Boolean] true when termination is complete | ||
def kill | ||
@mutex.synchronize do | ||
@state = SHUTDOWN | ||
@pool.each(&:kill) | ||
@pool.clear | ||
@queue.clear | ||
end | ||
true | ||
end | ||
|
||
# Gracefully shuts down the executor, optionally with a timeout. | ||
# Stops accepting new tasks and waits for running tasks to complete. | ||
# | ||
# @param timeout [Numeric, nil] Maximum time in seconds to wait for shutdown. | ||
# If nil, waits indefinitely. If timeout expires, remaining threads are killed. | ||
# @return [Boolean] true when shutdown is complete | ||
def shutdown(timeout = nil) | ||
@mutex.synchronize do | ||
return true if @state == SHUTDOWN | ||
|
||
@state = SHUTTING_DOWN | ||
@pool.size.times { @queue << :shutdown } | ||
end | ||
|
||
if timeout | ||
jterapin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
deadline = Time.now + timeout | ||
@pool.each do |thread| | ||
remaining = deadline - Time.now | ||
break if remaining <= 0 | ||
|
||
thread.join([remaining, 0].max) | ||
end | ||
@pool.select(&:alive?).each(&:kill) | ||
else | ||
@pool.each(&:join) | ||
end | ||
|
||
@mutex.synchronize do | ||
@pool.clear | ||
@state = SHUTDOWN | ||
end | ||
true | ||
end | ||
|
||
private | ||
|
||
def ensure_worker_available | ||
return unless @state == RUNNING | ||
|
||
@pool.select!(&:alive?) | ||
@pool << spawn_worker if @pool.size < @max_threads | ||
end | ||
|
||
def spawn_worker | ||
Thread.new do | ||
while (job = @queue.shift) | ||
break if job == :shutdown | ||
|
||
args, block = job | ||
block.call(*args) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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.
Uh oh!
There was an error while loading. Please reload this page.