From e805d69d8450eb73a78303bec3ad960023ad544b Mon Sep 17 00:00:00 2001 From: Holger Just Date: Fri, 26 Jan 2018 18:02:07 +0100 Subject: [PATCH] Use low-level IO#syswrite instead of IO#write in File adapter Since 1. we are using binmode and do not expect any conversation of newlines or encodings to take place, and 2. we are only writing to the open file when we have squired the mutex of the adapter instance we can safely use the syswrite method to write logs. In the end, this uses the same low-level syscall as `IO#write` but with less overhead. --- lib/rackstash/adapter/file.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/rackstash/adapter/file.rb b/lib/rackstash/adapter/file.rb index 0559184..e7e0a3d 100644 --- a/lib/rackstash/adapter/file.rb +++ b/lib/rackstash/adapter/file.rb @@ -129,7 +129,7 @@ module Rackstash @mutex.synchronize do auto_reopen - @file.write(line) + @file.syswrite(line) end nil end @@ -180,8 +180,7 @@ module Rackstash file = ::File.new( filename, - ::File::WRONLY | ::File::APPEND | ::File::CREAT, - external_encoding: Encoding::UTF_8 + ::File::WRONLY | ::File::APPEND | ::File::CREAT ) file.binmode file.sync = true