1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/net/http
normal 7db24a6269 net/http: use writev for HTTP chunked request bodies
This reduces both user and system CPU time for large
uploads with dynamically-generated request bodies.

              user     system      total        real
before:   0.393334   1.580000   1.973334 (  1.971066)
after:    0.223334   0.976666   1.200000 (  1.198514)

------
require 'socket'
require 'net/http'
require 'benchmark'
nr = 1024 * 1024 * 1024
s = TCPServer.new('127.0.0.1', 0)
addr = s.addr
at_exit { Process.waitall }
fork do
  c = s.accept
  # not exactly accurate but fast
  IO.copy_stream(c, '/dev/null', nr + 500000)
  begin
    buf = c.readpartial(16384)
    tmp = ''
    until buf.end_with?(-"0\r\n\r\n")
      buf << c.readpartial(16384, tmp)
    end
  rescue EOFError
  end
  c.write "HTTP/1.1 201 Created\r\nConnection:close\r\n\r\n"
  c.close
end
r, w = IO.pipe
fork do
  r.close
  IO.copy_stream('/dev/zero', w, nr)
  w.close
end
w.close
Net::HTTP.start(addr[3], addr[1]) do |http|
  put = Net::HTTP::Put.new('/dev0/foo')
  put['Content-Type'] = 'application/content-type'
  put['Transfer-Encoding'] = 'chunked'
  put.body_stream = r
  puts(Benchmark.measure { http.request(put) })
end
------

* lib/net/http/generic_request.rb (write): use multi-arg write
* lib/net/protocol.rb (write): support multi-arg
  (write0): ditto
  [ruby-core:84845] [Feature #14339]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-14 02:44:53 +00:00
..
backward.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
exceptions.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
generic_request.rb net/http: use writev for HTTP chunked request bodies 2018-01-14 02:44:53 +00:00
header.rb raise error if value contains CR/LF in iniheader of initialize_http_header 2017-12-20 12:06:59 +00:00
proxy_delta.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
request.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
requests.rb Add frozen_string_literal: false for all files 2015-12-16 05:07:31 +00:00
response.rb net/http: clear compressed chunk after decompression 2018-01-08 10:23:27 +00:00
responses.rb Update Status Code 2018-01-06 04:55:07 +00:00
status.rb Add 103 Early Hints to Net::HTTP::STATUS_CODES [ci skip] 2018-01-12 00:16:59 +00:00