Kouhei Sutou
null+****@clear*****
Sun Mar 23 21:34:26 JST 2014
Kouhei Sutou 2014-03-23 21:34:26 +0900 (Sun, 23 Mar 2014) New Revision: e86f18f17b7901663c334b8117f2bea21c905abd https://github.com/droonga/droonga-client-ruby/commit/e86f18f17b7901663c334b8117f2bea21c905abd Message: droonga-send: add --report-throughput option Modified files: bin/droonga-send Modified: bin/droonga-send (+42 -0) =================================================================== --- bin/droonga-send 2014-03-23 21:20:46 +0900 (9423664) +++ bin/droonga-send 2014-03-23 21:34:26 +0900 (8e9a18b) @@ -24,6 +24,7 @@ require "droonga/client" options = OpenStruct.new options.report_request = false +options.report_throughput = false servers = [] default_server = "droonga:localhost:24224/droonga" @@ -39,6 +40,37 @@ def parse_server(server) } end +class ThroughputReporter + def initialize + @start_time = Time.now + @measure_start_time = Time.now + @n_sent_messages = 0 + @first_report = true + end + + def on_message_sent + @n_sent_messages += 1 + current_time = Time.now + measure_span_in_second = current_time - @measure_start_time + if measure_span_in_second > 1 + messages_per_second = @n_sent_messages / measure_span_in_second + if @first_report + @first_report = false + else + move_to_previous_line + end + print("% 8.3f messages/second\n" % messages_per_second) + @n_sent_messages = 0 + @measure_start_time = current_time + end + end + + private + def move_to_previous_line + print("\e[1A\r") + end +end + parser = OptionParser.new parser.banner += " REQUEST_JSON_FILE1 REQUEST_JSON_FILE2 ..." parser.separator("") @@ -63,6 +95,11 @@ parser.on("--[no-]report-request", "(#{options[:report_request]})") do |report_request| options.report_request = report_request end +parser.on("--report-throughput", + "Reports throughput by messages per second.", + "(no)") do + options.report_throughput = true +end request_json_files = parser.parse!(ARGV) servers << default_server if servers.empty? @@ -72,6 +109,10 @@ clients = servers.collect do |server| Droonga::Client::RateLimiter.new(client, messages_per_second) end +if options.report_throughput + throughput_reporter = ThroughputReporter.new +end + client_index = 0 json_parser = Yajl::Parser.new json_parser.on_parse_complete = lambda do |request_message| @@ -88,6 +129,7 @@ json_parser.on_parse_complete = lambda do |request_message| client = clients[client_index] client.send(request_message) client_index = (client_index + 1) % clients.size + throughput_reporter.on_message_sent if throughput_reporter end if request_json_files.empty? -------------- next part -------------- HTML����������������������������...Download