1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib
normal 436eef270d net/http: clear compressed chunk after decompression
We no longer need the compressed data once the inflate block is
called; so clear it ASAP to reduce memory overhead.  This is a
small chunk, so it only saves a few hundred kilobytes with the
script below.

before:        RssAnon:     5976 kB
 after:        RssAnon:     5564 kB
------
require 'net/http'
require 'zlib'
response_gz = ARGV.shift or abort "#$0 TEMPORARY_FILE"

 # pre-create response since compressing is slower than decompressing
unless File.readable?(response_gz)
  nr = 16384 * 2
  buf = ((0..255).map(&:chr).join * 128)
  File.open(response_gz, 'wb') do |fp|
    gzip = Zlib::GzipWriter.new(fp)
    nr.times { gzip.write(buf) }
    gzip.close
  end
  buf.clear
end
response_gz = File.open(response_gz)

s = TCPServer.new('127.0.0.1', 0)
pid = fork do
  c = s.accept
  c.readpartial(16384).clear
  c.write("HTTP/1.1 200 OK\r\n" \
          "Content-Length: #{response_gz.stat.size}\r\n" \
          "Content-Encoding: gzip\r\n" \
          "Accept-Ranges: bytes\r\n" \
          "\r\n")
  IO.copy_stream(response_gz, c)
  c.close
end

addr = s.addr
Net::HTTP.start(addr[3], addr[1]) do |http|
  http.request_get(-'/') do |res|
    res.read_body(&:clear)
  end
end
puts File.readlines(-'/proc/self/status').grep(/RssAnon/)[0]
Process.waitpid2(pid)
------
* lib/net/http/response.rb (inflate_adapter): clear compressed_chunk

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08 10:23:27 +00:00
..
cgi
drb drb: use \A and \z 2017-12-30 12:10:43 +00:00
forwardable
irb proc.c (bind_location): Add Binding#source_location 2017-12-26 08:38:35 +00:00
matrix
net net/http: clear compressed chunk after decompression 2018-01-08 10:23:27 +00:00
optparse
racc
rdoc fix reset order. 2017-12-31 00:06:34 +00:00
rexml
rinda
rss
rubygems fix leaked fds 2017-12-25 05:54:27 +00:00
shell
unicode_normalize
uri
webrick webrick 1.4.2 2017-12-24 08:38:43 +00:00
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 $SAFE as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
fileutils.gemspec Bump up fileutils-1.0.2 2017-12-22 08:00:10 +00:00
fileutils.rb Bump up fileutils-1.0.2 2017-12-22 08:00:10 +00:00
find.rb
forwardable.rb
getoptlong.rb
ipaddr.gemspec
ipaddr.rb
irb.rb irb.rb: fix highlight 2017-12-25 07:55:25 +00:00
logger.rb * lib/logger.rb (Logger::LogDevice#open_logfile, #create_logfile): 2017-12-21 05:07:43 +00:00
matrix.rb
mkmf.rb int (*)(void) is incompatible with void* 2018-01-02 06:41:42 +00:00
monitor.rb
mutex_m.rb
observer.rb
open-uri.rb open-uri: clear string after buffering 2018-01-08 01:11:33 +00:00
open3.rb
optionparser.rb
optparse.rb
ostruct.rb
pp.rb Requiring pp is not required now [ci skip] 2017-12-18 01:51:53 +00:00
prettyprint.rb
prime.rb
profile.rb
profiler.rb
pstore.rb
rdoc.rb Merge rdoc-6.0.1. 2017-12-23 23:33:09 +00:00
resolv-replace.rb
resolv.rb Fixed command Injection 2017-12-20 04:25:01 +00:00
rss.rb
rubygems.rb Postponing the Bundler merge. 2017-12-22 23:08:05 +00:00
scanf.gemspec
scanf.rb lib/scanf.rb: [DOC] fix typos 2018-01-07 17:49:46 +00:00
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