Merge pull request #51740 from heka1024/parallel-upload-in-mirror-service
Improve performance in `ActiveStorage::Service::MirrorService`
This commit is contained in:
commit
3a2ec9bb3a
@ -30,6 +30,13 @@ def self.build(primary:, mirrors:, name:, configurator:, **options) # :nodoc:
|
||||
|
||||
def initialize(primary:, mirrors:)
|
||||
@primary, @mirrors = primary, mirrors
|
||||
@executor = Concurrent::ThreadPoolExecutor.new(
|
||||
min_threads: 1,
|
||||
max_threads: mirrors.size,
|
||||
max_queue: 0,
|
||||
fallback_policy: :caller_runs,
|
||||
idle_time: 60
|
||||
)
|
||||
end
|
||||
|
||||
# Upload the +io+ to the +key+ specified to all services. The upload to the primary service is done synchronously
|
||||
@ -75,10 +82,12 @@ def each_service(&block)
|
||||
end
|
||||
|
||||
def perform_across_services(method, *args)
|
||||
# FIXME: Convert to be threaded
|
||||
each_service.collect do |service|
|
||||
tasks = each_service.collect do |service|
|
||||
Concurrent::Promise.execute(executor: @executor) do
|
||||
service.public_send method, *args
|
||||
end
|
||||
end
|
||||
tasks.each(&:value!)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user