YUKI Hiroshi
null+****@clear*****
Fri Oct 11 10:24:47 JST 2013
YUKI Hiroshi 2013-10-11 10:24:47 +0900 (Fri, 11 Oct 2013) New Revision: 923029927422694308301880b1ad37b223e2eb1b https://github.com/droonga/drnbench/commit/923029927422694308301880b1ad37b223e2eb1b Message: Reduce indent Modified files: lib/droonga/benchmark/client/http.rb lib/droonga/benchmark/result.rb Modified: lib/droonga/benchmark/client/http.rb (+47 -47) =================================================================== --- lib/droonga/benchmark/client/http.rb 2013-10-11 10:23:44 +0900 (279776b) +++ lib/droonga/benchmark/client/http.rb 2013-10-11 10:24:47 +0900 (e6c3a48) @@ -6,64 +6,64 @@ require "json" module Droonga module Benchmark - class HttpClient - attr_reader :requests, :results, :wait + class HttpClient + attr_reader :requests, :results, :wait - DEFAULT_PATH = "/" - DEFAULT_METHOD = "GET" + DEFAULT_PATH = "/" + DEFAULT_METHOD = "GET" - def initialize(params) - @requests = params[:requests] - @result = params[:result] - @wait = params[:wait] + def initialize(params) + @requests = params[:requests] + @result = params[:result] + @wait = params[:wait] - @default_host = params[:host] - @default_port = params[:port] - @default_path = params[:path] || DEFAULT_PATH - @default_method = params[:method] || DEFAULT_METHOD - end + @default_host = params[:host] + @default_port = params[:port] + @default_path = params[:path] || DEFAULT_PATH + @default_method = params[:method] || DEFAULT_METHOD + end - def run - @thread = Thread.new do - loop do - request =****@reque***** - request[:host] ||= @default_host - request[:port] ||= @default_port - request[:path] ||= @default_path - request[:method] ||= @default_method - request[:method] = request[:method].upcase + def run + @thread = Thread.new do + loop do + request =****@reque***** + request[:host] ||= @default_host + request[:port] ||= @default_port + request[:path] ||= @default_path + request[:method] ||= @default_method + request[:method] = request[:method].upcase - Net::HTTP.start(request[:host], request[:port]) do |http| - header = { - "user-agent" => "Ruby/#{RUBY_VERSION} Droonga::Benchmark::Runner::HttpClient" - } - response = nil - start_time = Time.now - case request[:method] - when "GET" - response = http.get(request[:path], header) - when "POST" - body = request[:body] - unless body.is_a?(String) - body = JSON.generate(body) - end - response = http.post(request[:path], body, header) + Net::HTTP.start(request[:host], request[:port]) do |http| + header = { + "user-agent" => "Ruby/#{RUBY_VERSION} Droonga::Benchmark::Runner::HttpClient" + } + response = nil + start_time = Time.now + case request[:method] + when "GET" + response = http.get(request[:path], header) + when "POST" + body = request[:body] + unless body.is_a?(String) + body = JSON.generate(body) end - @result << { - :request => request, - :status => response.code, - :elapsed_time => Time.now - start_time, - } + response = http.post(request[:path], body, header) end - sleep @wait + @result << { + :request => request, + :status => response.code, + :elapsed_time => Time.now - start_time, + } end + sleep @wait end - self end + self + end - def stop - @thread.exit - end + def stop + @thread.exit end + end end end Modified: lib/droonga/benchmark/result.rb (+88 -88) =================================================================== --- lib/droonga/benchmark/result.rb 2013-10-11 10:23:44 +0900 (9e97c24) +++ lib/droonga/benchmark/result.rb 2013-10-11 10:24:47 +0900 (41308bf) @@ -2,113 +2,113 @@ module Droonga module Benchmark - class Result - attr_reader :n_clients, :duration, :statuses - - class << self - def keys - [ - :n_clients, - :total_n_requests, - :queries_per_second, - :min_elapsed_time, - :max_elapsed_time, - :average_elapsed_time, - ] - end + class Result + attr_reader :n_clients, :duration, :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] + def initialize(params) + @n_clients = params[:n_clients] + @duration = params[:duration] - @results = [] - @total_elapsed_time = 0.0 - @elapsed_times = [] - @statuses = {} - end + @results = [] + @total_elapsed_time = 0.0 + @elapsed_times = [] + @statuses = {} + end - def <<(result) - clear_cached_statistics + def <<(result) + clear_cached_statistics - @results << result + @results << result - @statuses[result[:status]] ||= 0 - @statuses[result[:status]] += 1 + @statuses[result[:status]] ||= 0 + @statuses[result[:status]] += 1 - @elapsed_times << result[:elapsed_time] - @total_elapsed_time += result[:elapsed_time] - end + @elapsed_times << result[:elapsed_time] + @total_elapsed_time += result[:elapsed_time] + end - def total_n_requests - @total_n_requests ||=****@resul***** - end + def total_n_requests + @total_n_requests ||=****@resul***** + end - def queries_per_second - @queries_per_second ||= total_n_requests.to_f / @duration - end + def queries_per_second + @queries_per_second ||= total_n_requests.to_f / @duration + end - def status_percentages - @status_percentages ||= prepare_status_percentages - end + def status_percentages + @status_percentages ||= prepare_status_percentages + end - def min_elapsed_time - @min_elapsed_time ||= @elapsed_times.min - end + def min_elapsed_time + @min_elapsed_time ||= @elapsed_times.min + end - def max_elapsed_time - @max_elapsed_time ||= @elapsed_times.min - end + def max_elapsed_time + @max_elapsed_time ||= @elapsed_times.min + end - def average_elapsed_time - @average_elapsed_time ||= @total_elapsed_time / @elapsed_times.size - end + def average_elapsed_time + @average_elapsed_time ||= @total_elapsed_time / @elapsed_times.size + end - def to_s - "Total requests: #{total_n_requests} " + - "(#{queries_per_second} queries per second)\n" + - "Status:\n" + - status_percentages.collect do |status, percentage| - " #{status}: #{percentage} %" - end.join("\n") + "\n" + - "Elapsed time:\n" + - " min: #{min_elapsed_time} sec\n" + - " max: #{max_elapsed_time} sec\n" + - " average: #{average_elapsed_time} sec" - end + def to_s + "Total requests: #{total_n_requests} " + + "(#{queries_per_second} queries per second)\n" + + "Status:\n" + + status_percentages.collect do |status, percentage| + " #{status}: #{percentage} %" + end.join("\n") + "\n" + + "Elapsed time:\n" + + " min: #{min_elapsed_time} sec\n" + + " max: #{max_elapsed_time} sec\n" + + " average: #{average_elapsed_time} sec" + end - def values - self.class.keys.collect do |column| - send(column) - end + def values + self.class.keys.collect do |column| + send(column) end + end - private - def clear_cached_statistics - @total_n_requests = nil - @queries_per_second = nil - @status_percentages = nil - @min_elapsed_time = nil - @max_elapsed_time = nil - @average_elapsed_time = nil - end + private + def clear_cached_statistics + @total_n_requests = nil + @queries_per_second = nil + @status_percentages = nil + @min_elapsed_time = nil + @max_elapsed_time = nil + @average_elapsed_time = nil + end - def prepare_status_percentages - status_percentages = [] - @statuses.each do |status, n_results| - percentage = n_results.to_f / total_n_requests * 100 - status_percentages << {:percentage => percentage, - :status => status} - end - status_percentages.sort! do |a, b| - (-1) * (a[:percentage] <=> b[:percentage]) - end - status_percentages = {} - status_percentages.each do |status| - status_percentages[status[:status]] = status[:percentage] - end - status_percentages + def prepare_status_percentages + status_percentages = [] + @statuses.each do |status, n_results| + percentage = n_results.to_f / total_n_requests * 100 + status_percentages << {:percentage => percentage, + :status => status} + end + status_percentages.sort! do |a, b| + (-1) * (a[:percentage] <=> b[:percentage]) + end + status_percentages = {} + status_percentages.each do |status| + status_percentages[status[:status]] = status[:percentage] end + status_percentages end + end end end -------------- next part -------------- HTML����������������������������... Download