Skip to content
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

Improve performance in ActiveStorage::Service::MirrorService #51740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions activestorage/lib/active_storage/service/mirror_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do a performance benchmarking?

Copy link
Contributor Author

@heka1024 heka1024 May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I'll add performance benchmark and request review to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akhilgkrishnan
This is performance benchmark using GCS. In my opinion, there is a performance improvement when looking at real time.

  • repeat time: 10

  • Used service: Google Cloud Storage (region: ap-northeast-3)

  • Used image size: 512kb

  • primary: 1, mirrors: 2

Task Real Time User Time System Time Total Time
Parallel 0.453 0.055 0.015 0.070
Sequential 0.979 0.045 0.011 0.056
  • primary: 1, mirrors: 1
Task Real Time User Time System Time Total Time
Parallel 0.380 0.053 0.020 0.074
Sequential 0.624 0.033 0.008 0.041

Copy link
Contributor Author

@heka1024 heka1024 May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akhilgkrishnan Could you please review when you get a chance? 😄

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
Expand Down Expand Up @@ -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|
service.public_send method, *args
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