Skip to content

Commit

Permalink
Adjust the buffer write function to clear the buffer once, rather tha…
Browse files Browse the repository at this point in the history
…n piece by piece. This avoids a case where a large write (in our case, around 70mbytes) will consume 100% of CPU. This takes a webrick GET request via SSL from around 200kbyts/sec and consuming 100% of a core, to line speed on gigabit ethernet and 6% cpu utlization.
  • Loading branch information
anotherjaymz committed Dec 12, 2023
1 parent 1fa9fc5 commit 2dee91d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/openssl/buffering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,17 @@ def do_write(s)
@wbuffer << s
@wbuffer.force_encoding(Encoding::BINARY)
@sync ||= false
if @sync or @wbuffer.size > BLOCK_SIZE
until @wbuffer.empty?
buffer_size = @wbuffer.size
if @sync or buffer_size > BLOCK_SIZE
nwrote = 0
while nwrote < buffer_size do
begin
nwrote = syswrite(@wbuffer)
nwrote += syswrite(@wbuffer)
rescue Errno::EAGAIN
retry
end
@wbuffer[0, nwrote] = ""
end
@wbuffer[0, nwrote] = ""
end
end

Expand Down

0 comments on commit 2dee91d

Please sign in to comment.