Skip to content

Instantly share code, notes, and snippets.

@tompave
Created March 14, 2018 11:13
Show Gist options
  • Save tompave/14730ba50454320e8ec63e579c1a2e0b to your computer and use it in GitHub Desktop.
Save tompave/14730ba50454320e8ec63e579c1a2e0b to your computer and use it in GitHub Desktop.
Find the memory overhead of threads in Ruby
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