mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
7db24a6269
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 |
||
---|---|---|
.. | ||
cgi | ||
drb | ||
forwardable | ||
irb | ||
matrix | ||
net | ||
optparse | ||
racc | ||
rdoc | ||
rexml | ||
rinda | ||
rss | ||
rubygems | ||
shell | ||
unicode_normalize | ||
uri | ||
webrick | ||
yaml | ||
.document | ||
abbrev.rb | ||
base64.rb | ||
benchmark.rb | ||
cgi.rb | ||
cmath.gemspec | ||
cmath.rb | ||
csv.gemspec | ||
csv.rb | ||
debug.rb | ||
delegate.rb | ||
drb.rb | ||
e2mmap.rb | ||
English.rb | ||
erb.rb | ||
fileutils.gemspec | ||
fileutils.rb | ||
find.rb | ||
forwardable.rb | ||
getoptlong.rb | ||
ipaddr.gemspec | ||
ipaddr.rb | ||
irb.rb | ||
logger.rb | ||
matrix.rb | ||
mkmf.rb | ||
monitor.rb | ||
mutex_m.rb | ||
observer.rb | ||
open-uri.rb | ||
open3.rb | ||
optionparser.rb | ||
optparse.rb | ||
ostruct.rb | ||
pp.rb | ||
prettyprint.rb | ||
prime.rb | ||
profile.rb | ||
profiler.rb | ||
pstore.rb | ||
rdoc.rb | ||
resolv-replace.rb | ||
resolv.rb | ||
rss.rb | ||
rubygems.rb | ||
scanf.gemspec | ||
scanf.rb | ||
securerandom.rb | ||
set.rb | ||
shell.rb | ||
shellwords.rb | ||
singleton.rb | ||
sync.rb | ||
tempfile.rb | ||
thwait.rb | ||
time.rb | ||
timeout.rb | ||
tmpdir.rb | ||
tracer.rb | ||
tsort.rb | ||
un.rb | ||
uri.rb | ||
weakref.rb | ||
webrick.rb | ||
yaml.rb |