Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Last active July 14, 2017 15:32
Show Gist options
  • Save SamSaffron/859eec0c5a87c29f39c438471461e030 to your computer and use it in GitHub Desktop.
Save SamSaffron/859eec0c5a87c29f39c438471461e030 to your computer and use it in GitHub Desktop.
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
@SamSaffron
Copy link
Author

allocated memory by class

1049568 Thread

@SamSaffron
Copy link
Author

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

@SamSaffron
Copy link
Author

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