From d7cf682fa83a72fd586ea738e6171ba5b3425d83 Mon Sep 17 00:00:00 2001 From: "Urabe, Shyouhei" Date: Sat, 28 Mar 2015 09:29:16 +0900 Subject: [PATCH] avoid repeated call of write(2) system call TCPSocket#write results in write(2) system call by default, and is heavy. One such call per a message is mandary, though anything more than that are waste of time. Lets just let the socket buffer things. --- lib/fluent/plugin/out_keep_forward.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/fluent/plugin/out_keep_forward.rb b/lib/fluent/plugin/out_keep_forward.rb index 9792b48..1cadad9 100644 --- a/lib/fluent/plugin/out_keep_forward.rb +++ b/lib/fluent/plugin/out_keep_forward.rb @@ -200,6 +200,9 @@ def reconnect(node) end def sock_write(sock, tag, chunk) + oldsync = sock.sync + sock.sync = false + # beginArray(2) sock.write FORWARD_HEADER @@ -221,6 +224,10 @@ def sock_write(sock, tag, chunk) # writeRawBody(packed_es) chunk.write_to(sock) + + ensure + sock.sync = oldsync + sock.flush # for immediate call of write(2) end # watcher thread callback