Created
March 14, 2018 11:13
-
-
Save tompave/14730ba50454320e8ec63e579c1a2e0b to your computer and use it in GitHub Desktop.
Find the memory overhead of threads in Ruby
This file contains 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 memory_kb | |
`ps -o rss= -p #{Process.pid}`.chomp.to_i | |
end | |
MEM_LOG = "current memory: %{mem} kB (+%{incr})".freeze | |
THR_LOG = "New Thread!".freeze | |
current_mem = 0 | |
loop do | |
m = memory_kb() | |
puts MEM_LOG % { mem: m, incr: m - current_mem } | |
current_mem = m | |
Thread.new do | |
puts THR_LOG | |
sleep 10_000 | |
end | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment