最近何かレスポンス遅くね?って言う時、
ab_bisect.rb
require 'systemu'
systemu 'bundle'
systemu 'bundle exec rails s -d'
sleep 5
# abコマンドでベンチマーク
status, stdout, stderr = systemu "ab -n 10 -c 10 'http://0.0.0.0:3000/'"
Process.kill 'KILL', `cat tmp/pids/server.pid`.to_i
sleep 3
# Requests per secondを抽出
stdout =~ /Requests per second:\s+([0-9\.]+)/
request_per_second = $1.to_f
puts "request_per_second: #{request_per_second}"
if request_per_second < 1.0 # ここの条件は環境によって調整する
puts 'bad'
exit 1
end
puts 'good'
exit 0
こんな感じのスクリプトを書いて、git bisectを実行
$ git bisect start HEAD [正常だったときのコミットハッシュ値]
$ git bisect run ruby ab_bisect.rb
あとはコーヒーを飲みながら待つだけ