YUKI Hiroshi
null+****@clear*****
Fri Jan 17 16:47:57 JST 2014
YUKI Hiroshi 2014-01-17 16:47:57 +0900 (Fri, 17 Jan 2014) New Revision: a7b65654c5debbebb56a80d6ed1eeedc3142fca3 https://github.com/droonga/drnbench/commit/a7b65654c5debbebb56a80d6ed1eeedc3142fca3 Message: Use configuration object for drnbench-publish Added files: lib/drnbench/publish/configuration.rb Modified files: bin/drnbench-publish lib/drnbench.rb lib/drnbench/publish/gradual-runner.rb lib/drnbench/publish/runner.rb Modified: bin/drnbench-publish (+24 -43) =================================================================== --- bin/drnbench-publish 2014-01-17 16:29:28 +0900 (36fb042) +++ bin/drnbench-publish 2014-01-17 16:47:57 +0900 (269c08e) @@ -2,106 +2,87 @@ # -*- coding: utf-8 -*- require "drnbench" -require "drnbench/server/configuration" require "optparse" -engine_config = Drnbench::Server::EngineConfiguration.new -protocol_adapter_config = Drnbench::Server::ProtocolAdapterConfiguration.new -protocol_adapter_config.engine_config = engine_config - -options = { - :start_n_subscribers => 1000, - :n_publishings => 1000, - :n_steps => 10, - :timeout => 10, - :report_progressively => true, - :output_path => "/tmp/drnbench-publish-result.csv", - - :subscribe_request => nil, - :feed => nil, -} +config = Drnbench::Publish::Configuration.new option_parser = OptionParser.new do |parser| parser.on("--start-n-subscribers=N", Integer, "initial number of subscribers") do |n_subscribers| - options[:start_n_subscribers] = n_subscribers + config.start_n_subscribers = n_subscribers end parser.on("--n-publishings=N", Integer, "number of publish times") do |n_publishings| - options[:n_publishings] = n_publishings + config.n_publishings = n_publishings end parser.on("--n-steps=N", Integer, "number of benchmark steps") do |n_steps| - options[:n_steps] = n_steps + config.n_steps = n_steps end parser.on("--timeout=SECONDS", Float, "timeout for receiving") do |timeout| - options[:timeout] = timeout + config.timeout = timeout end parser.on("--output-path=PATH", String, "path to the output CSV file") do |output_path| - options[:output_path] = output_path + config.output_path = output_path end parser.on("--subscribe-request=PATH", String, "path to the file which defines a request to subscribe") do |path| - options[:subscribe_request] = path + config.subscribe_request = path end parser.on("--feed=PATH", String, "path to the file which defines a message feeded to the engine") do |path| - options[:feed] = path + config.feed = path end parser.on("--protocol-adapter-port=PORT", Integer, "port number for the Droonga Protocol Adapter which is used for clients") do |port| - protocol_adapter_config.port = port + config.protocol_adapter.port = port end parser.on("--protocol-adapter-receive-port=PORT", Integer, "port number for the Droonga Protocol Adapter which is used for the engine") do |port| - protocol_adapter_config.receive_port = port + config.protocol_adapter.receive_port = port end parser.on("--protocol-adapter-application-dir=PATH", String, "path to the directory of the Droonga Protocol Adapter") do |path| - protocol_adapter_config.application_dir = path + config.protocol_adapter.application_dir = path end parser.on("--node=PATH", String, "path to the node.js executable") do |node| - protocol_adapter_config.node = node + config.protocol_adapter.node = node end parser.on("--node-options=OPTIONS", "options for node.js", "you can specify this option multiple times") do |options| - protocol_adapter_config.node_options = Shellwords.split(options) + config.protocol_adapter.node_options = Shellwords.split(options) end parser.on("--engine-config-path=PATH", String, "path to the configuration directory for Droonga Engine") do |path| - engine_config.engine_config_path = path + config.engine.engine_config_path = path end parser.on("--fluentd=PATH", String, "path to the fluentd executable") do |fluentd| - engine_config.fluentd = fluentd + config.engine.fluentd = fluentd end parser.on("--fluentd-options=OPTIONS", "options for fluentd", "you can specify this option multiple times") do |options| - engine_config.fluentd_options = Shellwords.split(options) + config.engine.fluentd_options = Shellwords.split(options) end end args = option_parser.parse!(ARGV) -if options[:subscribe_request].nil? - raise "You must specify a message pattern to subscribe, by --subscribe-request option." -end -if options[:feed].nil? - raise "You must specify a message pattern to feed, by --feed option." -end +config.validate -options[:engine_config] = engine_config -options[:protocol_adapter_config] = protocol_adapter_config -runner = Drnbench::Publish::GradualRunner.new(options) +runner = Drnbench::Publish::GradualRunner.new(config) runner.run -File.open(options[:output_path], "w") do |file| - file.puts runner.result.to_csv +File.open(@config.output_path, "w") do |file| + runner.total_results.each do |row| + file.puts(CSV.generate_line(row)) + puts row.join(",") + end end -puts "Statistics has been saved to #{options[:output_path]}" +puts "Statistics has been saved to #{config.output_path}" Modified: lib/drnbench.rb (+3 -0) =================================================================== --- lib/drnbench.rb 2014-01-17 16:29:28 +0900 (3b9290b) +++ lib/drnbench.rb 2014-01-17 16:47:57 +0900 (ec309b3) @@ -4,3 +4,6 @@ require "drnbench/version" require "drnbench/shuttle/configuration" require "drnbench/shuttle/runner" require "drnbench/shuttle/gradual-runner" +require "drnbench/publish/configuration" +require "drnbench/publish/runner" +require "drnbench/publish/gradual-runner" Added: lib/drnbench/publish/configuration.rb (+61 -0) 100644 =================================================================== --- /dev/null +++ lib/drnbench/publish/configuration.rb 2014-01-17 16:47:57 +0900 (d71c30f) @@ -0,0 +1,61 @@ +require "drnbench/server/configuration" + +module Drnbench + module Publish + class Configuration + attr_accessor :start_n_subscribers, :n_publishings, :n_steps, :timeout + attr_accessor :subscribe_request_file, :feed_file, :engine, :protocol_adapter + attr_accessor :report_progressively, :output_path + + def initialize + @start_n_subscribers = 1000 + @n_publishings = 1000 + @n_steps = 10 + @timeout = 10 + + @report_progressively = true + @output_path = "/tmp/drnbench-publish-result.csv" + + @engine = Server::EngineConfiguration.new + @protocol_adapter = Server::ProtocolAdapterConfiguration.new + @protocol_adapter.engine = @engine + end + + def validate + if @subscribe_request_file.nil? + raise ArgumentError.new("You must specify a JSON file for a message pattern to subscribe.") + end + if @feed_file_file.nil? + raise ArgumentError.new("You must specify a JSON file for a message pattern to feed.") + end + end + + def subscribe_request + @subscribe_request ||= prepare_subscribe_request + end + + def new_subscribe_request + Marshal.load(Marshal.dump(subscribe_request)) + end + + def feed + @feed ||= prepare_feed + end + + def new_feed + Marshal.load(Marshal.dump(feed)) + end + + private + def prepare_subscribe_request + subscribe_request_file = Pathname(@subscribe_request_file).expand_path(Dir.pwd) + JSON.parse(subscribe_request_file.read, :symbolize_names => true) + end + + def prepare_feed + feed_file = Pathname(@feed_file).expand_path(Dir.pwd) + JSON.parse(feed_file.read, :symbolize_names => true) + end + end + end +end Modified: lib/drnbench/publish/gradual-runner.rb (+16 -25) =================================================================== --- lib/drnbench/publish/gradual-runner.rb 2014-01-17 16:29:28 +0900 (9b8bd28) +++ lib/drnbench/publish/gradual-runner.rb 2014-01-17 16:47:57 +0900 (da80dc5) @@ -6,48 +6,39 @@ 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]) + attr_reader :total_results + + def initialize(config) + @config = config + @runner = Runner.new(@config) end def run results = [] - @params[:n_steps].times do |try_count| + @config.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 + percentage = published_messages.size.to_f / @config.n_publishings * 100 end end - puts "=> #{percentage} % feeds are notified" + if****@confi*****_progressively + puts "=> #{percentage} % feeds are notified" + end result = result.join("").strip.gsub(/[()]/, "").split(/\s+/) - qps = @params[:n_publishings].to_f / result.last.to_f - puts " (#{qps} queries per second)" + qps =****@confi*****_publishings.to_f / result.last.to_f + if****@confi*****_progressively + puts " (#{qps} queries per second)" + end results << [label, qps] end - total_results = [ + @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 + @total_results += results end end end Modified: lib/drnbench/publish/runner.rb (+8 -20) =================================================================== --- lib/drnbench/publish/runner.rb 2014-01-17 16:29:28 +0900 (a6a6d42) +++ lib/drnbench/publish/runner.rb 2014-01-17 16:47:57 +0900 (050a099) @@ -12,34 +12,22 @@ module Drnbench 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) + def initialize(config) + @config = config @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 = Engine.new(@config.engine) @engine.start - @protocol_adapter = ProtocolAdapter.new(@config.protocol_adapter_config) + @protocol_adapter = ProtocolAdapter.new(@config.protocol_adapter) @protocol_adapter.start end @@ -49,16 +37,16 @@ module Drnbench end def setup_initial_subscribers - add_subscribers(@params[:start_n_subscribers]) + add_subscribers(@config.start_n_subscribers) end def run - @n_publishings.times do |index| + @config.n_publishings.times do |index| do_feed end published_messages = [] - while published_messages.size != @n_publishings + while published_messages.size !=****@confi*****_publishings published_messages << @receiver.new_message end @@ -77,7 +65,7 @@ module Drnbench end def do_feed - message = Marshal.load(Marshal.dump(@feed)) + message =****@confi*****_feed message[:id] = Time.now.to_f.to_s, message[:date] = Time.now message[:statusCode] = 200 -------------- next part -------------- HTML����������������������������... Descargar