forked from bensheldon/good_job
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_job_throughput.rb
80 lines (67 loc) · 2.55 KB
/
benchmark_job_throughput.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# To run:
# bundle exec ruby scripts/benchmark_job_throughput.rb
#
ENV['GOOD_JOB_EXECUTION_MODE'] = 'external'
require_relative '../spec/test_app/config/environment'
require_relative '../lib/good_job'
require 'benchmark/ips'
require 'pry'
booleans = [true, false]
priorities = (1..10).to_a
scheduled_minutes = (-60..60).to_a
queue_names = ["one", "two", "three"]
GoodJob::Execution.delete_all
puts "Seeding database"
executions_data = Array.new(10_000) do |i|
puts "Initializing seed record ##{i}" if (i % 1_000).zero?
{
queue_name: queue_names.sample,
priority: priorities.sample,
scheduled_at: booleans.sample ? scheduled_minutes.sample.minutes.ago : nil,
created_at: 90.minutes.ago,
updated_at: 90.minutes.ago,
finished_at: booleans.sample ? scheduled_minutes.sample.minutes.ago : nil,
serialized_params: {},
}
end
puts "Inserting seed records into the database...\n"
GoodJob::Execution.insert_all(executions_data)
# ActiveRecord::Base.connection.execute('SET enable_seqscan = OFF')
Benchmark.ips do |x|
x.report("without sorts") do
GoodJob::Execution.unfinished.only_scheduled.limit(1).with_advisory_lock do |executions|
# executions.first&.destroy!
end
end
x.report("sort by priority only") do
GoodJob::Execution.unfinished.priority_ordered.only_scheduled.limit(1).with_advisory_lock do |executions|
# executions.first&.destroy!
end
end
x.report("sort by creation only") do
GoodJob::Execution.unfinished.creation_ordered.only_scheduled.limit(1).with_advisory_lock do |executions|
# executions.first&.destroy!
end
end
x.report("sort by priority and creation") do
GoodJob::Execution.unfinished.priority_ordered.creation_ordered.only_scheduled.limit(1).with_advisory_lock do |executions|
# executions.first&.destroy!
end
end
x.report("sort by ordered queues only") do
GoodJob::Execution.unfinished.queue_ordered(%w{one two three}).creation_ordered.only_scheduled.limit(1).with_advisory_lock do |executions|
# executions.first&.destroy!
end
end
x.report("sort by ordered queues and creation") do
GoodJob::Execution.unfinished.queue_ordered(%w{one two three}).creation_ordered.only_scheduled.limit(1).with_advisory_lock do |executions|
# executions.first&.destroy!
end
end
x.report("sort by ordered queues, priority, and creation") do
GoodJob::Execution.unfinished.queue_ordered(%w{one two three}).priority_ordered.creation_ordered.only_scheduled.limit(1).with_advisory_lock do |executions|
# executions.first&.destroy!
end
end
x.compare!
end