-
Notifications
You must be signed in to change notification settings - Fork 346
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
feat: add maximum concurrent threads by using Parallel gem #398
Conversation
Pull Request Test Coverage Report for Build 404
💛 - Coveralls |
Travis tests have failedHey @RickCSong, Ruby: 2.3rake
Ruby: 2.5rake
Ruby: 2.6rake
Ruby: 2.7rake
Ruby: ruby-headrake
Ruby: jruby-headrake
TravisBuddy Request Identifier: babbb6a0-5398-11ea-87d9-d7aacf6f1a64 |
Travis tests have failedHey @RickCSong, Ruby: 2.3rake
Ruby: 2.5rake
Ruby: 2.6rake
Ruby: 2.7rake
Ruby: ruby-headrake
Ruby: jruby-headrake
TravisBuddy Request Identifier: a22ca5a0-539c-11ea-87d9-d7aacf6f1a64 |
Travis tests have failedHey @RickCSong, Ruby: 2.3rake
Ruby: 2.5rake
Ruby: 2.6rake
Ruby: 2.7rake
Ruby: ruby-headrake
Ruby: jruby-headrake
TravisBuddy Request Identifier: 578aac00-53a0-11ea-87d9-d7aacf6f1a64 |
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.
Got several changes
- Rename
concurrent_max_threads
->concurrent_uploads_max_threads
Ensure this setting is for uploading files only - Use
Queue#close
added since ruby 2.3 instead ofrescue ThreadError
https://hspazio.github.io/2017/ruby-threads-and-queues/
I modified the code from the article above to use Queue#close
require "thread"
work = Queue.new
(1..10).each do |i|
work.push(i)
end
work.close
num_consumers = 2
consumers = Array.new(num_consumers) do |n|
Thread.new do
while job = work.pop
puts "consumer #{n}: #{job}"
# simulate some work to do
sleep 2
end
end
end
consumers.map(&:join)
e9f9616
to
0a32759
Compare
This is really great feedback @PikachuEXE ! I've updated the PR accordingly -- great callout on using I've also added tests since I believe we are generally happy with the direction of this change :) |
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.
There is a merge conflict to be resolved :)
lib/asset_sync/storage.rb
Outdated
threads.add(Thread.new { upload_file f }) | ||
workers = Array.new(num_threads) do | ||
Thread.new do | ||
begin |
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.
Why do you still need begin..end
in Thread
block?
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.
Good catch!!! Fixed.
@RickCSong |
Before, asset_sync would create a separate thread for every asset that was uplaoded. When there are a large number of assets being uploaded, this could lead to processes crashing due to too many threads being created. By limiting the number of threads, this speeds up performance while preventing crashes from resource starvation.
Sorry @PikachuEXE ! Done. |
Released in |
Before, asset_sync would create a separate thread for every asset that
was uplaoded. When there are a large number of assets being uploaded,
this could lead to processes crashing due to too many threads being
created.
By limiting the number of threads, this speeds up
performance while preventing crashes from resource starvation.
See: #395