Skip to content

Commit fbd8fad

Browse files
committed
Update benchmark comparison.
1 parent 859121e commit fbd8fad

16 files changed

+210
-375
lines changed

examples/benchmark/async-job-client.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/benchmark/async-job-server.rb

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024-2025, by Samuel Williams.
5+
# Copyright, 2025, by Shopify Inc.
6+
7+
require "active_job"
8+
require "async/job/adapter/active_job"
9+
10+
class AsyncJobBenchmarkJob < ActiveJob::Base
11+
self.queue_adapter = :async_job
12+
queue_as :default
13+
14+
def perform(index)
15+
PERFORMANCE_LOG.write "{index: #{index}, start_time: #{Process.clock_gettime(Process::CLOCK_MONOTONIC)}}\n"
16+
17+
sleep(0.001)
18+
19+
PERFORMANCE_LOG.write "{index: #{index}, end_time: #{Process.clock_gettime(Process::CLOCK_MONOTONIC)}}\n"
20+
PERFORMANCE_LOG.flush
21+
end
22+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# Released under the MIT License.
5+
# Copyright, 2024-2025, by Samuel Williams.
6+
# Copyright, 2025, by Shopify Inc.
7+
8+
require_relative "config/environment"
9+
10+
def benchmark_async_job(job_count = 10_000)
11+
puts "Benchmarking async-job with #{job_count} jobs..."
12+
13+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
14+
15+
Sync do
16+
job_count.times do |index|
17+
AsyncJobBenchmarkJob.perform_later(index)
18+
end
19+
end
20+
21+
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
22+
23+
puts "Async-job results:"
24+
puts " Started at: #{start_time}"
25+
puts " Ended at: #{end_time}"
26+
puts " Total enqueue time: #{end_time - start_time}s"
27+
puts " Jobs per second: #{(job_count / (end_time - start_time)).round(2)}"
28+
end
29+
30+
# Parse command line argument for job count
31+
job_count = ARGV[0] ? ARGV[0].to_i : 10_000
32+
33+
if job_count <= 0
34+
puts "Error: Job count must be a positive integer"
35+
puts "Usage: #{$0} [job_count]"
36+
puts "Example: #{$0} 5000"
37+
exit 1
38+
end
39+
40+
benchmark_async_job(job_count)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env async-service
2+
# frozen_string_literal: true
3+
4+
# Released under the MIT License.
5+
# Copyright, 2024-2025, by Samuel Williams.
6+
# Copyright, 2025, by Shopify Inc.
7+
8+
require_relative "config/environment"
9+
require "async/job/adapter/active_job/environment"
10+
11+
service "async-job-server" do
12+
include Async::Job::Adapter::ActiveJob::Environment
13+
14+
count 1
15+
end

examples/benchmark/bake.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
def performance_log_rate
3+
File.open("performance.log", "r") do |file|
4+
start_time = nil
5+
end_time = nil
6+
count = 0
7+
8+
file.each_line do |line|
9+
line = eval(line.strip)
10+
if line[:start_time]
11+
if start_time.nil? or start_time > line[:start_time]
12+
start_time = line[:start_time]
13+
end
14+
elsif line[:end_time]
15+
if end_time.nil? or end_time < line[:end_time]
16+
end_time = line[:end_time]
17+
end
18+
count += 1
19+
end
20+
end
21+
22+
if start_time && end_time && count > 0
23+
rate = count / (end_time - start_time)
24+
puts "Processed #{count} jobs at #{rate.round(2)} jobs/sec"
25+
else
26+
puts "No jobs processed."
27+
end
28+
end
29+
end

examples/benchmark/benchmark_job.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/benchmark/config/environment.rb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,34 @@
77
require "rails"
88
require "active_job/railtie"
99
require "async/job/adapter/active_job/railtie"
10+
require "async/job/processor/aggregate"
11+
require "async/job/processor/redis"
1012

13+
ActiveJob::Base.logger = Logger.new(nil)
14+
PERFORMANCE_LOG = File.open("performance.log", "a")
15+
PERFORMANCE_LOG.sync = true
16+
17+
# Define async-job queue for async-job adapter
1118
Async::Job::Adapter::ActiveJob::Railtie.define_queue "default" do
12-
dequeue Async::Job::Queue::Redis
19+
enqueue Async::Job::Processor::Aggregate
20+
dequeue Async::Job::Processor::Redis
1321
end
1422

15-
ActiveJob::Base.queue_adapter = Async::Job::Adapter::ActiveJob::Railtie.config.active_job.queue_adapter
23+
require "sidekiq"
24+
25+
begin
26+
require "sidekiq-pro"
27+
require "sidekiq-ent"
28+
29+
Sidekiq::Client.reliable_push!
30+
31+
Sidekiq.configure_server do |config|
32+
config.super_fetch!
33+
config.reliable_scheduler!
34+
end
35+
rescue LoadError
36+
# Ignore.
37+
end
1638

17-
require_relative "../benchmark_job"
39+
require_relative "../async_job_benchmark_job"
40+
require_relative "../sidekiq_benchmark_job"

0 commit comments

Comments
 (0)