Skip to content

Instantly share code, notes, and snippets.

@SamSaffron

SamSaffron/test.rb

Last active Jul 14, 2017
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@SamSaffron SamSaffron commented Apr 27, 2017

allocated memory by class

1049568 Thread

@SamSaffron

This comment has been minimized.

Copy link
Owner Author

@SamSaffron SamSaffron commented Apr 27, 2017

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

This comment has been minimized.

Copy link
Owner Author

@SamSaffron SamSaffron commented Apr 27, 2017

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