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+ # Create a minimal Rails-like environment for SolidQueue
9+ ENV [ 'RAILS_ENV' ] ||= 'development'
10+
11+ require "bundler/setup"
12+ require "rails"
13+ require "active_job/railtie"
14+ require "active_record/railtie"
15+
16+ # Create a minimal Rails application
17+ class SolidQueueApp < Rails ::Application
18+ config . load_defaults 7.1
19+ config . eager_load = false
20+ config . logger = Logger . new ( nil ) # Quiet for client
21+ config . log_level = :error
22+
23+ # Don't configure ActiveJob for our simple database queue
24+ end
25+
26+ # Initialize the Rails app
27+ Rails . application . initialize!
28+
29+ # Set up database connection - use correct path in benchmark directory
30+ database_path = File . join ( __dir__ , 'db' , 'solid_queue.sqlite3' )
31+ puts "Connecting to database: #{ database_path } "
32+
33+ ActiveRecord ::Base . establish_connection (
34+ adapter : 'sqlite3' ,
35+ database : database_path
36+ )
37+
38+ # Simple database-backed job model (instead of complex SolidQueue setup)
39+ class SimpleSolidJob < ActiveRecord ::Base
40+ self . table_name = 'solid_queue_jobs'
41+ end
42+
43+ # Clear ActiveRecord cache and verify connection
44+ ActiveRecord ::Base . clear_cache!
45+ puts "Database connection: #{ ActiveRecord ::Base . connection . database_version } "
46+ puts "Tables available: #{ ActiveRecord ::Base . connection . tables . join ( ', ' ) } "
47+
48+ # Load our job
49+ require_relative "solid_queue_benchmark_job"
50+
51+ def benchmark_solid_queue ( job_count = 10_000 )
52+ puts "Benchmarking solid_queue with #{ job_count } jobs..."
53+
54+ start_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
55+
56+ job_count . times do
57+ # Insert job directly into database instead of using ActiveJob
58+ SimpleSolidJob . create! (
59+ job_class : 'SolidQueueBenchmarkJob' ,
60+ job_args : '[]' ,
61+ queue_name : 'solid_queue_default' ,
62+ priority : 0 ,
63+ created_at : Time . current ,
64+ updated_at : Time . current
65+ )
66+ end
67+
68+ end_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
69+
70+ puts "SolidQueue results:"
71+ puts " Started at: #{ start_time } "
72+ puts " Ended at: #{ end_time } "
73+ puts " Total enqueue time: #{ end_time - start_time } s"
74+ puts " Jobs per second: #{ ( job_count / ( end_time - start_time ) ) . round ( 2 ) } "
75+ end
76+
77+ # Parse command line argument for job count
78+ job_count = ARGV [ 0 ] ? ARGV [ 0 ] . to_i : 10_000
79+
80+ if job_count <= 0
81+ puts "Error: Job count must be a positive integer"
82+ puts "Usage: #{ $0} [job_count]"
83+ puts "Example: #{ $0} 5000"
84+ exit 1
85+ end
86+
87+ benchmark_solid_queue ( job_count )
0 commit comments