YUKI Hiroshi
yuki****@clear*****
Fri Jan 17 10:28:43 JST 2014
そもそもこれはparamsをそのままRunnerに渡してしまってよい場面なんですよね…… 試行錯誤を繰り返した結果をコミットしたので、整理されきっていない状態のま まの部分が残っていたという感じです。 Kouhei Sutou wrote: >> + class GradualRunner >> + def initialize(params) >> + @params = params >> + @runner = Runner.new(:start_n_subscribers => @params[:start_n_subscribers], >> + :n_publishings => @params[:n_publishings], >> + :timeout => @params[:timeout], >> + :subscribe_request => @params[:subscribe_request], >> + :feed => @params[:feed], >> + :engine_config => @params[:engine_config], >> + :protocol_adapter_config => @params[:protocol_adapter_config]) >> + end >> + > > このparamってConfigurationオブジェクトを渡すとすっきりしませ > ん。bin/drnbench-publishでHashにいろいろ値を設定していますが、 > それをConfigurationオブジェクトに設定するように変えるとその > まま渡せると思います。 > > In <e9546d5ec0d943ef27bbd83955736ed3a8eb83e2 �� jenkins.clear-code.com> > "[Groonga-commit] droonga/drnbench �� e9546d5 [master] Add partial implementation of runners for drnbench-publish" on Fri, 17 Jan 2014 09:56:27 +0900, > YUKI Hiroshi <null+groonga �� clear-code.com> wrote: > >> YUKI Hiroshi 2014-01-17 09:56:27 +0900 (Fri, 17 Jan 2014) >> >> New Revision: e9546d5ec0d943ef27bbd83955736ed3a8eb83e2 >> https://github.com/droonga/drnbench/commit/e9546d5ec0d943ef27bbd83955736ed3a8eb83e2 >> >> Message: >> Add partial implementation of runners for drnbench-publish >> >> Added files: >> lib/drnbench/publish/gradual-runner.rb >> lib/drnbench/publish/runner.rb >> lib/drnbench/publish/watch.rb >> >> Added: lib/drnbench/publish/gradual-runner.rb (+54 -0) 100644 >> =================================================================== >> --- /dev/null >> +++ lib/drnbench/publish/gradual-runner.rb 2014-01-17 09:56:27 +0900 (9b8bd28) >> @@ -0,0 +1,54 @@ >> +# -*- coding: utf-8 -*- >> + >> +require "benchmark" >> +require "csv" >> + >> +module Drnbench >> + module Publish >> + class GradualRunner >> + def initialize(params) >> + @params = params >> + @runner = Runner.new(:start_n_subscribers => @params[:start_n_subscribers], >> + :n_publishings => @params[:n_publishings], >> + :timeout => @params[:timeout], >> + :subscribe_request => @params[:subscribe_request], >> + :feed => @params[:feed], >> + :engine_config => @params[:engine_config], >> + :protocol_adapter_config => @params[:protocol_adapter_config]) >> + end >> + >> + def run >> + results = [] >> + @params[:n_steps].times do |try_count| >> + @runner.add_subscribers(@runner.n_subscribers) if try_count > 0 >> + label = "#{@runner.n_subscribers} subscribers" >> + percentage = nil >> + result = Benchmark.bm do |benchmark| >> + benchmark.report(label) do >> + published_messages =****@runne***** >> + percentage = published_messages.size.to_f / @params[:n_publishings] * 100 >> + end >> + end >> + puts "=> #{percentage} % feeds are notified" >> + result = result.join("").strip.gsub(/[()]/, "").split(/\s+/) >> + qps = @params[:n_publishings].to_f / result.last.to_f >> + puts " (#{qps} queries per second)" >> + results << [label, qps] >> + end >> + total_results = [ >> + ["case", "qps"], >> + ] >> + total_results += results >> + >> + puts "" >> + puts "Results (saved to #{@params[:output_path]}):" >> + File.open(@params[:output_path], "w") do |file| >> + total_results.each do |row| >> + file.puts(CSV.generate_line(row)) >> + puts row.join(",") >> + end >> + end >> + end >> + end >> + end >> +end >> >> Added: lib/drnbench/publish/runner.rb (+88 -0) 100644 >> =================================================================== >> --- /dev/null >> +++ lib/drnbench/publish/runner.rb 2014-01-17 09:56:27 +0900 (a6a6d42) >> @@ -0,0 +1,88 @@ >> +# -*- coding: utf-8 -*- >> + >> +require "json" >> +require "yajl" >> +require "pathname" >> +require "droonga/client" >> +require "drnbench/server/engine" >> +require "drnbench/server/protocol-adapter" >> + >> +module Drnbench >> + module Publish >> + class Runner >> + attr_reader :n_subscribers >> + >> + def initialize(params) >> + @params = params || {} >> + >> + @n_publishings = params[:n_publishings] || 0 >> + @timeout = params[:timeout] || 0 >> + >> + subscribe_request_file = @params[:subscribe_request] >> + subscribe_request_file = Pathname(subscribe_request_file).expand_path(Dir.pwd) >> + @subscribe_request = JSON.parse(subscribe_request_file.read, :symbolize_names => true) >> + >> + feed_file = @params[:feed] >> + feed_file = Pathname(feed_file).expand_path(Dir.pwd) >> + @feed = JSON.parse(feed_file.read, :symbolize_names => true) >> + >> + @n_subscribers = 0 >> + >> + @feeder = Droonga::Client.new(tag: "droonga", port: 23003) >> + >> + @server_config = @params[:server_config] >> + setup_server >> + setup_initial_subscribers >> + end >> + >> + def setup_server >> + @engine = Engine.new(@config.engine_config) >> + @engine.start >> + >> + @protocol_adapter = ProtocolAdapter.new(@config.protocol_adapter_config) >> + @protocol_adapter.start >> + end >> + >> + def teardown_server >> + @protocol_adapter.stop >> + @engine.stop >> + end >> + >> + def setup_initial_subscribers >> + add_subscribers(@params[:start_n_subscribers]) >> + end >> + >> + def run >> + @n_publishings.times do |index| >> + do_feed >> + end >> + >> + published_messages = [] >> + while published_messages.size != @n_publishings >> + published_messages << @receiver.new_message >> + end >> + >> + teardown_server >> + published_messages >> + end >> + >> + def add_subscribers(n_subscribers) >> + n_subscribers.times do |index| >> + @request[:path] >> + @request[:method] >> + @request[:body] >> + @client.connection.send(message, :response => :one) >> + end >> + @n_subscribers += n_subscribers >> + end >> + >> + def do_feed >> + message = Marshal.load(Marshal.dump(@feed)) >> + message[:id] = Time.now.to_f.to_s, >> + message[:date] = Time.now >> + message[:statusCode] = 200 >> + @feeder.connection.send(message, :response => :none) >> + end >> + end >> + end >> +end >> >> Added: lib/drnbench/publish/watch.rb (+28 -0) 100644 >> =================================================================== >> --- /dev/null >> +++ lib/drnbench/publish/watch.rb 2014-01-17 09:56:27 +0900 (bba39cd) >> @@ -0,0 +1,28 @@ >> +require "droonga/watch_schema" >> + >> +module Drnbench >> + module Publish >> + class Watch >> + class << self >> + def command >> + "watch" >> + end >> + >> + def subscribe(keyword) >> + { >> + "condition" => keyword, >> + "subscriber" => "subscriber for #{keyword}", >> + } >> + end >> + >> + def feed(keyword) >> + { >> + "targets" => { >> + "keyword" => keyword, >> + }, >> + } >> + end >> + end >> + end >> + end >> +end > > _______________________________________________ > Groonga-commit mailing list > Groonga-commit �� lists.sourceforge.jp > http://lists.sourceforge.jp/mailman/listinfo/groonga-commit > -- 結城 洋志 <YUKI Hiroshi> E-mail: yuki �� clear-code.com 株式会社クリアコード 〒113-0033 東京都文京区本郷3-27-12 本郷デントビル2階 TEL : 03-6231-7270 FAX : 03-6231-7271 WWW : http://www.clear-code.com/