Project

General

Profile

Feature #14237

[PATCH 0/2] webrick: use IO.copy_stream

Added by normalperson (Eric Wong) 29 days ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:84456]

Description

First patch is prepatory, second patch uses IO.copy_stream:

https://80x24.org/spew/20171226043936.7694-1-e@80x24.org/raw
https://80x24.org/spew/20171226043936.7694-2-e@80x24.org/raw

It should support Content-Range in a 3rd (to-be-written) patch,
too.

[PATCH 2/2] webrick/httpresponse: IO.copy_stream for regular files

Remove the redundant _send_file method since its functionality
is unnecessary with IO.copy_stream. IO.copy_stream also allows
the use of sendfile under some OSes to speed up copies to
non-TLS sockets.

Testing with "curl >/dev/null" and "ruby -run -e httpd" to
read a 1G file over Linux loopback reveals a reduction from
around ~0.770 to ~0.490 seconds on the client side.

  • lib/webrick/httpresponse.rb (send_body_io): use IO.copy_stream (_send_file): remove

[PATCH 1/2] webrick: favor .write over << method

This will make the next change to use IO.copy_stream
easier-to-read. When we can drop Ruby 2.4 support in a few
years, this will allow us to use writev(2) with multiple
arguments for headers and chunked responses.

  • lib/webrick/cgi.rb (write): new wrapper method lib/webrick/httpresponse.rb (_write_data): remove (send_header): use socket.write (send_body_io): ditto (send_body_string): ditto (send_body_proc): ditto (ChunkedWrapper#write): ditto (_send_file): ditto

Also available in: Atom PDF