From 98b663091a919035ea85bc5273bfe4bd1aac2073 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 1 Nov 2013 22:01:45 +0000 Subject: wbuf: only enable bypass if we've truncated The first time we call wbuf_write, we do so because we already hit :wait_writable in the caller. So we can avoid the extra still-highly-likely-to-return-:wait_*) kgio_trywrite by writing to the VFS, first. --- lib/yahns/wbuf.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb index 10312db..8b2b82e 100644 --- a/lib/yahns/wbuf.rb +++ b/lib/yahns/wbuf.rb @@ -11,20 +11,19 @@ class Yahns::Wbuf # :nodoc: @sf_offset = @sf_count = 0 @wbuf_persist = persist # whether or not we keep the connection alive @body = body + @bypass = false end def wbuf_write(client, buf) # try to bypass the VFS layer if we're all caught up - if @sf_count == 0 - case rv = client.kgio_trywrite(buf) - when String - buf = rv # retry in loop - when nil - return nil # yay! hopefully we don't have to buffer again - when :wait_writable, :wait_readable - break # ugh, continue to buffering to file - end while true - end + case rv = client.kgio_trywrite(buf) + when String + buf = rv # retry in loop + when nil + return # yay! hopefully we don't have to buffer again + when :wait_writable, :wait_readable + @bypass = false # ugh, continue to buffering to file + end while @bypass @sf_count += @tmpio.write(buf) case rv = client.trysendfile(@tmpio, @sf_offset, @sf_count) @@ -42,6 +41,7 @@ class Yahns::Wbuf # :nodoc: # to disk if we can help it. @tmpio.truncate(@sf_offset = 0) @tmpio.rewind + @bypass = true nil end -- cgit v1.2.3-24-ge0c7