Last active
July 14, 2017 15:32
-
-
Save SamSaffron/859eec0c5a87c29f39c438471461e030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recurse(i) | |
recurse(i-1) if i > 0 | |
end | |
threads = ARGV[0].to_i | |
puts "Running with #{threads} threads!" | |
threads.times do | |
Thread.new do | |
recurse(500) | |
sleep | |
puts "done" | |
end | |
end | |
require 'memory_profiler' | |
MemoryProfiler.report do | |
Thread.new{sleep 0.1} | |
end.pretty_print | |
sleep 1 | |
puts "#{Thread.list.count} threads running!" | |
sleep |
sam 18582 0.0 0.1 2665088 12896 s002 S+ 8:17am 0:00.09 ruby test.rb 100
sam 18568 0.0 0.2 3504496 35884 s001 S+ 8:17am 0:00.14 ruby test.rb 500
VSZ is is allocated, but only turns to RSS when used, you can see the impact via playing with recurse amount or setting stuff on thread storage.
So RSS impact depends on call stack depth and other stuff that is stored on the thread stack (local rvalues like numbers and params, thread local storage and so on)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
allocated memory by class
1049568 Thread