[Groonga-commit] droonga/fluent-plugin-droonga at 9caeb55 [master] Use UNIX domain socket instead of TCP socket for job queue mechanism

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Dec 11 18:39:48 JST 2013


Kouhei Sutou	2013-12-11 18:39:48 +0900 (Wed, 11 Dec 2013)

  New Revision: 9caeb55f16b9de5a2a11276aa39ed744d9b75f9c
  https://github.com/droonga/fluent-plugin-droonga/commit/9caeb55f16b9de5a2a11276aa39ed744d9b75f9c

  Message:
    Use UNIX domain socket instead of TCP socket for job queue mechanism
    
    Because TCP socket can't create many connections in short term. TCP
    has TIME_WAIT state. It is 60s by default on Linux. In TCP_WAIT state,
    we can't use the TCP port. If we create many TCP connections in short
    term, we use all available TCP ports soon.

  Modified files:
    lib/droonga/message_pusher.rb
    lib/droonga/partition.rb

  Modified: lib/droonga/message_pusher.rb (+8 -4)
===================================================================
--- lib/droonga/message_pusher.rb    2013-12-11 17:28:42 +0900 (e940379)
+++ lib/droonga/message_pusher.rb    2013-12-11 18:39:48 +0900 (cccadd3)
@@ -26,8 +26,11 @@ module Droonga
       @loop = EventLoop.new
     end
 
-    def start
-      @raw_receiver = TCPServer.new("127.0.0.1", 0)
+    def start(base_path)
+      socket_path = "#{base_path}.sock"
+      FileUtils.rm_f(socket_path)
+      @raw_receiver = UNIXServer.new(socket_path)
+      FileUtils.chmod(0600, socket_path)
       @loop_thread = Thread.new do
         @loop.run
       end
@@ -36,6 +39,7 @@ module Droonga
     def shutdown
       $log.trace("#{log_tag}: shutdown: start")
       @raw_receiver.close
+      FileUtils.rm_f(@raw_receiver.path)
       @loop.stop
       @loop_thread.join
       $log.trace("#{log_tag}: shutdown: done")
@@ -44,8 +48,8 @@ module Droonga
     def push(message)
       $log.trace("#{log_tag}: push: start")
       packed_message = message.to_msgpack
-      _, port, _, ip_address = @raw_receiver.addr
-      sender = Coolio::TCPSocket.connect(ip_address, port)
+      path = @raw_receiver.path
+      sender = Coolio::UNIXSocket.connect(path)
       sender.write(message.to_msgpack)
       sender.on_write_complete do
         close

  Modified: lib/droonga/partition.rb (+2 -1)
===================================================================
--- lib/droonga/partition.rb    2013-12-11 17:28:42 +0900 (661d5aa)
+++ lib/droonga/partition.rb    2013-12-11 18:39:48 +0900 (ffafd11)
@@ -35,7 +35,8 @@ module Droonga
     def start
       ensure_database
       @processor.start
-      @message_pusher.start
+      base_path = @options[:database]
+      @message_pusher.start(base_path)
       start_supervisor if @n_workers > 0
     end
 
-------------- next part --------------
HTML����������������������������...
下载 



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