YUKI Hiroshi
null+****@clear*****
Mon Oct 28 18:22:39 JST 2013
YUKI Hiroshi 2013-10-28 18:22:39 +0900 (Mon, 28 Oct 2013) New Revision: 0554f7c9f574774f24b2b86fbee3d47a72397778 https://github.com/droonga/fluent-plugin-droonga/commit/0554f7c9f574774f24b2b86fbee3d47a72397778 Message: Benchmark: rewrite to run benchmark with networking features Modified files: benchmark/benchmark.rb benchmark/watch/benchmark-notify.rb Modified: benchmark/benchmark.rb (+6 -2) =================================================================== --- benchmark/benchmark.rb 2013-10-28 18:22:11 +0900 (7e357a1) +++ benchmark/benchmark.rb 2013-10-28 18:22:39 +0900 (178dced) @@ -73,8 +73,8 @@ module Droonga @client.connection.send_receive(subscribe_envelope) end - def envelope_to_subscribe(term) - { + def envelope_to_subscribe(term, route=nil) + message = { "id" => Time.now.to_f.to_s, "date" => Time.now, "statusCode" => 200, @@ -84,6 +84,10 @@ module Droonga "subscriber" => term, }, } + unless route.nil? + message["body"]["route"] = route + end + message end def populate_feeds(incidence) Modified: benchmark/watch/benchmark-notify.rb (+30 -24) =================================================================== --- benchmark/watch/benchmark-notify.rb 2013-10-28 18:22:11 +0900 (dad437c) +++ benchmark/watch/benchmark-notify.rb 2013-10-28 18:22:39 +0900 (fa46fd5) @@ -15,52 +15,53 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# this benchmark must be done by benchmark-notify.sh. + require "benchmark" require "fileutils" require "optparse" require "csv" -require "groonga" +require "droonga/client" -require "droonga/watcher" require File.expand_path(File.join(__FILE__, "..", "..", "utils.rb")) class NotifyBenchmark attr_reader :n_subscribers - def initialize(n_initial_subscribers) - @database = DroongaBenchmark::WatchDatabase.new - @watcher = Droonga::Watcher.new(@database.context) - @keywords_generator = DroongaBenchmark::KeywordsGenerator.new - @keywords = [] + WATCHING_KEYWORD = "a" + + def initialize(params) + @params = params || {} + @n_times = params[:n_times] || 0 + @timeout = params[:timeout] || 0 + @n_subscribers = 0 - add_subscribers(n_initial_subscribers) + + @client = Droonga::Client.new(tag: "droonga", port: 23003) + @receiver = Droonga::Client::Connection::DroongaProtocol::Receiver.new + @route = "#{@receiver.host}:#{@receiver.port}/droonga" + add_subscribers(@params[:n_initial_subscribers]) end def run - @matched_keywords.each do |keyword| - publish(keyword) + @n_times.times do + do_feed(WATCHING_KEYWORD) end end - def prepare_keywords(n_keywords) - @matched_keywords =****@keywo*****(n_keywords) - end - def add_subscribers(n_subscribers) - new_keywords = [] n_subscribers.times do - new_keywords << @keywords_generator.next + message = DroongaBenchmark::MessageCreator.envelope_to_subscribe(WATCHING_KEYWORD, @route) + @client.connection.send_receive(message) end - @database.subscribe_to(new_keywords) - @keywords += new_keywords @n_subscribers += n_subscribers end - private - def publish(matched_keyword) - @watcher.publish([matched_keyword], {}) do |route, subscribers| - end + def do_feed(target) + message = DroongaBenchmark::MessageCreator.envelope_to_feed(target) + @client.connection.send(message) + @receiver.receive(:timeout => @timeout) end end @@ -83,6 +84,10 @@ option_parser = OptionParser.new do |parser| "number of benchmark steps (optional)") do |n_steps| options[:n_steps] = n_steps end + parser.on("--timeout=N", Float, + "timeout for receiving (optional)") do |timeout| + options[:timeout] = timeout + end parser.on("--output-path=PATH", String, "path to the output CSV file (optional)") do |output_path| options[:output_path] = output_path @@ -91,13 +96,14 @@ end args = option_parser.parse!(ARGV) -notify_benchmark = NotifyBenchmark.new(options[:n_subscribers]) +notify_benchmark = NotifyBenchmark.new(:n_initial_subscribers => options[:n_subscribers], + :n_times => options[:n_times], + :timeout => options[:timeout]) results = [] options[:n_steps].times do |try_count| notify_benchmark.add_subscribers(notify_benchmark.n_subscribers) if try_count > 0 label = "#{notify_benchmark.n_subscribers} subscribers" result = Benchmark.bmbm do |benchmark| - notify_benchmark.prepare_keywords(options[:n_times]) benchmark.report(label) do notify_benchmark.run end -------------- next part -------------- HTML����������������������������...Download