forked from appsignal/appsignal-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.rake
77 lines (64 loc) · 2.4 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
require 'appsignal'
require 'benchmark'
class ::Appsignal::Event::ActiveRecordEvent
def connection_config; {:adapter => 'mysql'}; end
end
GC.disable
namespace :benchmark do
task :all => [:run_inactive, :run_active] do
end
task :run_inactive do
puts 'Running with appsignal off'
ENV['APPSIGNAL_PUSH_API_KEY'] = nil
subscriber = ActiveSupport::Notifications.subscribe do |*args|
# Add a subscriber so we can track the overhead of just appsignal
end
run_benchmark
ActiveSupport::Notifications.unsubscribe(subscriber)
end
task :run_active do
puts 'Running with appsignal on'
ENV['APPSIGNAL_PUSH_API_KEY'] = 'something'
run_benchmark
end
end
def run_benchmark
total_objects = ObjectSpace.count_objects[:TOTAL]
puts "Initializing, currently #{total_objects} objects"
Appsignal.config = Appsignal::Config.new('', 'production')
Appsignal.start
puts "Appsignal #{Appsignal.active? ? 'active' : 'not active'}"
puts 'Running 10_000 normal transactions'
puts(Benchmark.measure do
10_000.times do |i|
Appsignal::Transaction.create("transaction_#{i}", {})
ActiveSupport::Notifications.instrument('sql.active_record', :sql => 'SELECT `users`.* FROM `users` WHERE `users`.`id` = ?')
10.times do
ActiveSupport::Notifications.instrument('sql.active_record', :sql => 'SELECT `todos`.* FROM `todos` WHERE `todos`.`id` = ?')
end
ActiveSupport::Notifications.instrument('render_template.action_view', :identifier => 'app/views/home/show.html.erb') do
5.times do
ActiveSupport::Notifications.instrument('render_partial.action_view', :identifier => 'app/views/home/_piece.html.erb') do
3.times do
ActiveSupport::Notifications.instrument('cache.read')
end
end
end
end
ActiveSupport::Notifications.instrument(
'process_action.action_controller',
:controller => 'HomeController',
:action => 'show',
:params => {:id => 1}
)
Appsignal::Transaction.complete_current!
end
end)
if Appsignal.active?
puts "Running aggregator post_processed_queue! for #{Appsignal.agent.aggregator.queue.length} transactions"
puts(Benchmark.measure do
Appsignal.agent.aggregator.post_processed_queue!.to_json
end)
end
puts "Done, currently #{ObjectSpace.count_objects[:TOTAL] - total_objects} objects created"
end