forked from appsignal/appsignal-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.rake
83 lines (68 loc) · 2.47 KB
/
benchmark.rake
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
81
82
83
require 'appsignal'
require 'benchmark'
def process_rss
`ps -o rss= -p #{Process.pid}`.to_i
end
GC.disable
task :default => :'benchmark:all'
namespace :benchmark do
task :all => [:run_inactive, :run_active]
task :run_inactive do
puts 'Running with appsignal off'
ENV['APPSIGNAL_PUSH_API_KEY'] = nil
run_benchmark
end
task :run_active do
puts 'Running with appsignal on'
ENV['APPSIGNAL_PUSH_API_KEY'] = 'something'
run_benchmark
end
end
def run_benchmark
no_transactions = (ENV['NO_TRANSACTIONS'] || 100_000).to_i
no_threads = (ENV['NO_THREADS'] || 1).to_i
total_objects = ObjectSpace.count_objects[:TOTAL]
puts "Initializing, currently #{total_objects} objects"
puts "RSS: #{process_rss}"
Appsignal.config = Appsignal::Config.new(Dir.pwd, 'production', :endpoint => 'http://localhost:8080')
Appsignal.start
puts "Appsignal #{Appsignal.active? ? 'active' : 'not active'}"
threads = []
puts "Running #{no_transactions} normal transactions in #{no_threads} threads"
puts(Benchmark.measure do
no_threads.times do
thread = Thread.new do
no_transactions.times do |i|
request = Appsignal::Transaction::GenericRequest.new(
:controller => 'HomeController',
:action => 'show',
:params => {:id => 1}
)
Appsignal::Transaction.create("transaction_#{i}", Appsignal::Transaction::HTTP_REQUEST, request)
Appsignal.instrument('process_action.action_controller') do
Appsignal.instrument_sql('sql.active_record', nil, 'SELECT `users`.* FROM `users` WHERE `users`.`id` = ?')
10.times do
Appsignal.instrument_sql('sql.active_record', nil, 'SELECT `todos`.* FROM `todos` WHERE `todos`.`id` = ?')
end
Appsignal.instrument('render_template.action_view', 'app/views/home/show.html.erb') do
5.times do
Appsignal.instrument('render_partial.action_view', 'app/views/home/_piece.html.erb') do
3.times do
Appsignal.instrument('cache.read')
end
end
end
end
end
Appsignal::Transaction.complete_current!
end
end
thread.abort_on_exception = true
threads << thread
end
threads.each(&:join)
puts 'Finished'
end)
puts "Done, currently #{ObjectSpace.count_objects[:TOTAL] - total_objects} objects created"
puts "RSS: #{process_rss}"
end