Skip to content

Instantly share code, notes, and snippets.

@tboyko
Last active March 25, 2018 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tboyko/943f52702fa9a623da56acd19130c141 to your computer and use it in GitHub Desktop.
Save tboyko/943f52702fa9a623da56acd19130c141 to your computer and use it in GitHub Desktop.
Shows how rss memory changes during usage of redis gem
require 'redis'
def Process.rss ; `ps -o rss= -p #{Process.pid}`.chomp.to_i ; end
def Process.pretty_rss
GC.start(full_mark: true, immediate_sweep: true)
Process.rss.to_s.gsub(/(\d)(?=(\d{3})+(\..*)?$)/,'\1,') + " kilobytes"
end
puts "start: #{Process.pretty_rss}"
r = Redis.new
r.del('test')
r = nil
puts "after cleanup: #{Process.pretty_rss}"
r = Redis.new
r.pipelined do
10000.times do
r.lpush('test', 'dummystring'*1000)
end
end
r = nil
puts "after insert: #{Process.pretty_rss}"
r = Redis.new
10000.times do
r.brpop('test')
end
r = nil
puts "after pop: #{Process.pretty_rss}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment