benchmark.rake in appsignal-2.1.0 vs benchmark.rake in appsignal-2.1.1.beta.1
- old
+ new
@@ -1,16 +1,14 @@
-require 'active_support'
require 'appsignal'
require 'benchmark'
GC.disable
task :default => :'benchmark:all'
namespace :benchmark do
- task :all => [:run_inactive, :run_active] do
- end
+ task :all => [:run_inactive, :run_active]
task :run_inactive do
puts 'Running with appsignal off'
ENV['APPSIGNAL_PUSH_API_KEY'] = nil
run_benchmark
@@ -22,47 +20,57 @@
run_benchmark
end
end
def run_benchmark
- no_transactions = 10_000
+ 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"
Appsignal.config = Appsignal::Config.new(Dir.pwd, 'production', :endpoint => 'http://localhost:8080')
Appsignal.start
puts "Appsignal #{Appsignal.active? ? 'active' : 'not active'}"
- puts "Running #{no_transactions} normal transactions"
+ threads = []
+ puts "Running #{no_transactions} normal transactions in #{no_threads} threads"
puts(Benchmark.measure 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)
+ 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
- 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
+ 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
- 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')
+ 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
-
- Appsignal::Transaction.complete_current!
+ 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"
end