Last active
March 25, 2018 15:26
-
-
Save tboyko/943f52702fa9a623da56acd19130c141 to your computer and use it in GitHub Desktop.
Shows how rss memory changes during usage of redis gem
This file contains hidden or 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
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