[Groonga-commit] droonga/fluent-plugin-droonga at 46429be [master] benchmark: use custom receiver instead of droonga-client's one

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Oct 28 20:39:14 JST 2013


YUKI Hiroshi	2013-10-28 20:39:14 +0900 (Mon, 28 Oct 2013)

  New Revision: 46429be7cc2b378c3b0579cfb07864fd00867842
  https://github.com/droonga/fluent-plugin-droonga/commit/46429be7cc2b378c3b0579cfb07864fd00867842

  Message:
    benchmark: use custom receiver instead of droonga-client's one

  Modified files:
    benchmark/utils.rb
    benchmark/watch/benchmark-notify.rb

  Modified: benchmark/utils.rb (+40 -0)
===================================================================
--- benchmark/utils.rb    2013-10-28 19:51:24 +0900 (1f37e5d)
+++ benchmark/utils.rb    2013-10-28 20:39:14 +0900 (f09d1a2)
@@ -199,4 +199,44 @@ module DroongaBenchmark
       end
     end
   end
+
+  class MessageReceiver
+    def initialize(options={})
+      default_options = {
+        :host => "0.0.0.0",
+        :port => 0,
+      }
+      options = default_options.merge(options)
+      @socket = TCPServer.new(options[:host], options[:port])
+    end
+
+    def close
+      @socket.close
+    end
+
+    def host
+      @socket.addr[3]
+    end
+
+    def port
+      @socket.addr[1]
+    end
+
+    def receive(options={})
+      waiting_count = options[:wait_for] || 1
+      if IO.select([@socket], nil, nil, options[:timeout])
+        client =****@socke*****
+        messages = []
+        unpacker = MessagePack::Unpacker.new(client)
+        unpacker.each do |object|
+          messages << object
+          break if messages.size >= waiting_count
+        end
+        client.close
+        messages
+      else
+        nil
+      end
+    end
+  end
 end

  Modified: benchmark/watch/benchmark-notify.rb (+4 -6)
===================================================================
--- benchmark/watch/benchmark-notify.rb    2013-10-28 19:51:24 +0900 (548c578)
+++ benchmark/watch/benchmark-notify.rb    2013-10-28 20:39:14 +0900 (1e7c42c)
@@ -40,7 +40,7 @@ class NotifyBenchmark
     @n_subscribers = 0
 
     @client = Droonga::Client.new(tag: "droonga", port: 23003)
-    @receiver = Droonga::Client::Connection::DroongaProtocol::Receiver.new
+    @receiver = DroongaBenchmark::MessageReceiver.new
     @route = "#{@receiver.host}:#{@receiver.port}/droonga"
     setup
   end
@@ -55,14 +55,12 @@ class NotifyBenchmark
   end
 
   def run
+    notifications = []
     @n_times.times do |index|
       do_feed("#{WATCHING_KEYWORD} #{index}")
     end
-    notifications = []
-    @n_times.times do
-      notification =****@recei*****(:timeout => @timeout)
-      notifications << notification unless notification.nil?
-    end
+    received =****@recei*****(:timeout => @timeout, :wait_for => @n_times)
+    notifications += received if received.is_a?(Array)
     notifications
   end
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index