13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

git bisectとApache Bench使って性能を下げる原因になったコミットを探す

Posted at

最近何かレスポンス遅くね?って言う時、

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

あとはコーヒーを飲みながら待つだけ

13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?