ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: milovan.zogovic@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95588] [Ruby master Bug#16284] Net/HTTP consuming multiple times more memories compared to other libraries
Date: Wed, 30 Oct 2019 12:14:15 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-16284.20191030121415.013540ea882230df@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16284.20191030121415@ruby-lang.org

Issue #16284 has been reported by zogash (Milovan Zogovic).

----------------------------------------
Bug #16284: Net/HTTP consuming multiple times more memories compared to other libraries
https://bugs.ruby-lang.org/issues/16284

* Author: zogash (Milovan Zogovic)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
I have an issue where Net/HTTP library is causing very high memory usage when requesting for medium to large sized content. 

Here is the script to reproduce the issue:

```
gem 'excon'

require 'uri'
require 'net/http'
require 'excon'

uri = URI('https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_1920_18MG.mp4')

def print_memory
  mem = `ps -o rss -p #{Process::pid}`.chomp.split("\n").last.strip.to_i
  puts "Memory: #{mem/1024} MB"
end

25.times do
  case ARGV[0]
  when 'EXCON' then Excon.get(uri.to_s)
  when 'NET' then Net::HTTP.get_response(uri)
  end
  print_memory
end

```

The script downloads 18MB size video file 25 times in a row and prints the process memory. After 25 iterations, `Net/HTTP` ends up almost 300MB of ram, while `Excon` only 60MB. Here is the complete result of RAM size the process used after each iteration:

```
> Excon
Memory: 41 MB
Memory: 60 MB
Memory: 95 MB
Memory: 58 MB
Memory: 95 MB
Memory: 49 MB
Memory: 55 MB
Memory: 51 MB
Memory: 71 MB
Memory: 66 MB
Memory: 58 MB
Memory: 65 MB
Memory: 89 MB
Memory: 76 MB
Memory: 83 MB
Memory: 64 MB
Memory: 75 MB
Memory: 98 MB
Memory: 64 MB
Memory: 58 MB
Memory: 63 MB
Memory: 69 MB
Memory: 75 MB
Memory: 70 MB
Memory: 54 MB

> Net::HTTP
Memory: 51 MB
Memory: 81 MB
Memory: 104 MB
Memory: 129 MB
Memory: 146 MB
Memory: 166 MB
Memory: 163 MB
Memory: 144 MB
Memory: 163 MB
Memory: 161 MB
Memory: 169 MB
Memory: 187 MB
Memory: 204 MB
Memory: 221 MB
Memory: 238 MB
Memory: 255 MB
Memory: 272 MB
Memory: 289 MB
Memory: 306 MB
Memory: 306 MB
Memory: 306 MB
Memory: 306 MB
Memory: 317 MB
Memory: 299 MB
Memory: 294 MB
```

I have tried with ruby 2.7.0-preview2 and the issue is present there as well.






-- 
https://bugs.ruby-lang.org/

       reply	other threads:[~2019-10-30 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16284.20191030121415@ruby-lang.org>
2019-10-30 12:14 ` milovan.zogovic [this message]
2019-10-30 14:10 ` [ruby-core:95589] [Ruby master Bug#16284] Net/HTTP consuming multiple times more memory compared to other libraries mame
2019-10-31  9:33 ` [ruby-core:95605] " milovan.zogovic
2019-12-16  7:31 ` [ruby-core:96258] " mame

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-16284.20191030121415.013540ea882230df@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).