diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-08 10:23:27 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-08 10:23:27 +0000 |
commit | 436eef270dc07af248db32ca7441ddaa0b6409a6 (patch) | |
tree | 90a707829cfc131f39df8596fe875b0a80fc103e /lib/net | |
parent | 79161d30bdb57626f84330e226afdec56ea46d13 (diff) | |
download | ruby-436eef270dc07af248db32ca7441ddaa0b6409a6.tar.gz |
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
Diffstat (limited to 'lib/net')
-rw-r--r-- | lib/net/http/response.rb | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb index 6a78272ac8..66132985d9 100644 --- a/lib/net/http/response.rb +++ b/lib/net/http/response.rb @@ -380,6 +380,7 @@ class Net::HTTPResponse end block = proc do |compressed_chunk| @inflate.inflate(compressed_chunk) do |chunk| + compressed_chunk.clear dest << chunk end end |