Kouhei Sutou
kou****@clear*****
Wed Oct 9 16:24:17 JST 2013
> + (result.values +
> + response_statuses.collect do |status|
> + result.response_statuses[status] || 0
> + end).join(",")
これは、やりすぎですかねぃ。。。
別の、to_sでjoin("\n") + "\n"しているやつもですけど。。。
In <066575113d6def75ee37c5554292a016393848fd �� jenkins.clear-code.com>
"[Groonga-commit] droonga/http-benchmark �� 0665751 [master] Implement GradualResult as a class" on Wed, 09 Oct 2013 16:17:44 +0900,
YUKI Hiroshi <null+groonga �� clear-code.com> wrote:
> YUKI Hiroshi 2013-10-09 16:17:44 +0900 (Wed, 09 Oct 2013)
>
> New Revision: 066575113d6def75ee37c5554292a016393848fd
> https://github.com/droonga/http-benchmark/commit/066575113d6def75ee37c5554292a016393848fd
>
> Message:
> Implement GradualResult as a class
>
> Modified files:
> lib/droonga/http-benchmark/formatter.rb
> lib/droonga/http-benchmark/gradual-runner.rb
> lib/droonga/http-benchmark/runner.rb
>
> Modified: lib/droonga/http-benchmark/formatter.rb (+0 -30)
> ===================================================================
> --- lib/droonga/http-benchmark/formatter.rb 2013-10-09 15:44:39 +0900 (f4c3c50)
> +++ lib/droonga/http-benchmark/formatter.rb 2013-10-09 16:17:44 +0900 (2da4b71)
> @@ -4,36 +4,6 @@ module Droonga
> module HttpBenchmark
> class Formatter
> class << self
> - def output_gradual_results(results)
> - http_statuses = []
> - results.each do |n_clients, result|
> - http_statuses += result[:responses].keys
> - end
> - http_statuses.uniq!
> - http_statuses.sort!
> -
> - puts "n_clients,total_n_requests,queries_per_second," +
> - "#{http_statuses.join(",")}," +
> - "min_elapsed_time,max_elapsed_time,average_elapsed_time"
> - results.each do |n_clients, result|
> - result[:n_clients] = n_clients
> - response_statuses = http_statuses.collect do |status|
> - if result[:responses].include?(status)
> - result[:responses][status]
> - else
> - 0
> - end
> - end
> - result[:response_statuses] = response_statuses.join(",")
> - puts(("%{n_clients}," +
> - "%{total_n_requests}," +
> - "%{queries_per_second}," +
> - "%{response_statuses}," +
> - "%{min_elapsed_time}," +
> - "%{max_elapsed_time}," +
> - "%{average_elapsed_time}") % result)
> - end
> - end
> end
> end
> end
>
> Modified: lib/droonga/http-benchmark/gradual-runner.rb (+46 -3)
> ===================================================================
> --- lib/droonga/http-benchmark/gradual-runner.rb 2013-10-09 15:44:39 +0900 (92f0e50)
> +++ lib/droonga/http-benchmark/gradual-runner.rb 2013-10-09 16:17:44 +0900 (cad558c)
> @@ -20,18 +20,61 @@ module Droonga
>
> def run
> run_benchmarks
> - Formatter.output_gradual_results(@results)
> + puts****@resul*****_csv
> end
>
> private
> def run_benchmarks
> - @results = {}
> + @result = GradualResult.new
> @start_n_clients.step(@end_n_clients, @step) do |n_clients|
> benchmark = Runner.new(@params.merge(:n_clients => n_clients))
> puts "Running benchmark with #{n_clients} clients..."
> - @results[n_clients] = benchmark.run
> + @result << benchmark.run
> end
> end
> end
> +
> + class GradualResult
> + def initialize
> + @results = {}
> + end
> +
> + def <<(result)
> + @response_statuses = nil
> + @results[result.n_clients] = result
> + end
> +
> + def response_statuses
> + @response_statuses ||= prepare_response_statuses
> + end
> +
> + def to_csv
> + "#{csv_header}\n#{csv_body}"
> + end
> +
> + private
> + def prepare_response_statuses
> + response_statuses = []
> + @results.each do |n_clients, result|
> + response_statuses += result.response_statuses.keys
> + end
> + response_statuses.uniq!
> + response_statuses.sort!
> + response_statuses
> + end
> +
> + def csv_header
> + (Result.keys + response_statuses).join(",")
> + end
> +
> + def csv_body
> + @results.values.collect do |result|
> + (result.values +
> + response_statuses.collect do |status|
> + result.response_statuses[status] || 0
> + end).join(",")
> + end.join("\n")
> + end
> + end
> end
> end
>
> Modified: lib/droonga/http-benchmark/runner.rb (+24 -1)
> ===================================================================
> --- lib/droonga/http-benchmark/runner.rb 2013-10-09 15:44:39 +0900 (838adb7)
> +++ lib/droonga/http-benchmark/runner.rb 2013-10-09 16:17:44 +0900 (aed5dc2)
> @@ -51,7 +51,8 @@ module Droonga
> private
> def process_requests
> requests_queue = Queue.new
> - @result = Result.new(:duration => @duration)
> + @result = Result.new(:n_clients => @n_clients,
> + :duration => @duration)
>
> @clients = @n_clients.times.collect do |index|
> client = Client.new(:requests => requests_queue,
> @@ -164,7 +165,23 @@ module Droonga
> end
>
> class Result
> + attr_reader :n_clients, :duration, :response_statuses
> +
> + class << self
> + def keys
> + [
> + :n_clients,
> + :total_n_requests,
> + :queries_per_second,
> + :min_elapsed_time,
> + :max_elapsed_time,
> + :average_elapsed_time,
> + ]
> + end
> + end
> +
> def initialize(params)
> + @n_clients = params[:n_clients]
> @duration = params[:duration]
>
> @results = []
> @@ -222,6 +239,12 @@ module Droonga
> " average: #{average_elapsed_time} sec"
> end
>
> + def values
> + self.class.keys.collect do |column|
> + send(column)
> + end
> + end
> +
> private
> def clear_cached_statistics
> @total_n_requests = nil