siege をラップして多少細かい情報をまとめる gem 書いた。
Usage
たとえば Rails 内でこうやる。
re = SiegeSiege.run( time: 20, concurrent: 4, user_agent: false, urls: [ "http://localhost:3002#{students_path}", "http://localhost:3002#{students_path} POST name=abc", SiegeSiege::URL.new("http://localhost:3002#{students_path}", :post, {name: 'abc'}), ] + Student.ids.shuffle[0..2].map { |id| "http://localhost:3002#{student_path(id)}" } )
するとこういうのが得られる。
普通に使ってもコンソールに出てきてたやつ
re.total_result => {:command=>"siege -v -c 4 -t 20s -r 1 -R /tmp/20161030-21093-1lo07ca -f /tmp/20161030-21093-13f1kj6", :defaulting_to_time_based_testing=>{:value=>20.0, :unit=>"seconds"}, :transactions=>{:value=>96.0, :unit=>"hits"}, :availability=>{:value=>75.0, :unit=>"%"}, :elapsed_time=>{:value=>19.47, :unit=>"secs"}, :data_transferred=>{:value=>2.03, :unit=>"MB"}, :response_time=>{:value=>0.8, :unit=>"secs"}, :transaction_rate=>{:value=>4.93, :unit=>"trans/sec"}, :throughput=>{:value=>0.1, :unit=>"MB/sec"}, :concurrency=>{:value=>3.93, :unit=>""}, :successful_transactions=>{:value=>96.0, :unit=>""}, :failed_transactions=>{:value=>32.0, :unit=>""}, :longest_transaction=>{:value=>10.65, :unit=>""}, :shortest_transaction=>{:value=>0.01, :unit=>""}}
アクセスに使った URL 毎に平均レスポンス時間とか
re.average_log => [#<struct SiegeSiege::AverageLog id=6, url="http://localhost:3002/students/10763", count=17, secs=0.691, siege_url=#<SiegeSiege::URL:0x007fbee6efe870 @http_method=:get, @parameter={}, @url="http://localhost:3002/students/10763">>, #<struct SiegeSiege::AverageLog id=0, url="http://localhost:3002/students", count=16, secs=1.276, siege_url=#<SiegeSiege::URL:0x007fbee6efeb18 @http_method=:get, @parameter={}, @url="http://localhost:3002/students">>, #<struct SiegeSiege::AverageLog id=5, url="http://localhost:3002/students/39284", count=16, secs=0.767, siege_url=#<SiegeSiege::URL:0x007fbee6efe938 @http_method=:get, @parameter={}, @url="http://localhost:3002/students/39284">>, #<struct SiegeSiege::AverageLog id=7, url="http://localhost:3002/students/94576", count=17, secs=0.108, siege_url=#<SiegeSiege::URL:0x007fbee6efe7a8 @http_method=:get, @parameter={}, @url="http://localhost:3002/students/94576">>, #<struct SiegeSiege::AverageLog id=3, url="http://localhost:3002/students", count=15, secs=1.367, siege_url=#<SiegeSiege::URL:0x007fbee6cd9518 @http_method=:post, @parameter={:name=>"abc"}, @url="http://localhost:3002/students">>, #<struct SiegeSiege::AverageLog id=1, url="http://localhost:3002/students", count=15, secs=0.651, siege_url=#<SiegeSiege::URL:0x007fbee6efea50 @http_method=:post, @parameter="name=abc", @url="http://localhost:3002/students">>]
標準出力をまとめたやつ
re.raw_log => [#<struct SiegeSiege::LineLog protocol="HTTP/1.1", status="200", secs=10.09, bytes=633, url="http://localhost:3002/students/10763", id=6, date=Sun, 30 Oct 2016 13:10:31 +0000, siege_url=#<SiegeSiege::URL:0x007fbee6efe870 @http_method=:get, @parameter={}, @url="http://localhost:3002/students/10763">>, #<struct SiegeSiege::LineLog protocol="HTTP/1.1", status="200", secs=10.29, bytes=45579, url="http://localhost:3002/students", id=0, date=Sun, 30 Oct 2016 13:10:31 +0000, siege_url=#<SiegeSiege::URL:0x007fbee6efeb18 @http_method=:get, @parameter={}, @url="http://localhost:3002/students">>, #<struct SiegeSiege::LineLog protocol="HTTP/1.1", status="200", secs=10.24, bytes=633, url="http://localhost:3002/students/39284", id=5, date=Sun, 30 Oct 2016 13:10:31 +0000, siege_url=#<SiegeSiege::URL:0x007fbee6efe938 @http_method=:get, @parameter={}, @url="http://localhost:3002/students/39284">>, #<struct SiegeSiege::LineLog protocol="HTTP/1.1", status="200", secs=0.25, bytes=633, url="http://localhost:3002/students/94576", id=7, date=Sun, 30 Oct 2016 13:10:41 +0000, siege_url=# # 略
所感
カジュアルにテストできて便利ですね、みたいなツールで、詳細な情報を取ろうとするのはやめといた方がいいと思いました。(適切なやつをさがそう)