Create a gist now

Instantly share code, notes, and snippets.

@SamSaffron /leak.rb
Last active Jul 31, 2017

Embed
What would you like to do?
i = 0
def parse_param(s)
unless block_given?
return enum_for(__method__, s)
end
yield "a"
nil
end
def parse_line(line)
parts = parse_param(';' + line)
parts.next
end
while i < 10_000
Thread.new { parse_line("Content-Type:application/json; charset=ISO-8859-1") }.join
slots = GC.stat[:heap_live_slots]
_,rss = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
puts "slots #{slots} #{i+=1} threads #{Thread.list.count} rss #{rss}"
end
puts "done #{RUBY_VERSION}"
gets
##
# Ruby 2.3.3
# slots 19183, rss 36980
# Ruby 2.4.1
# slots 14448, rss 132572
#
# Ruby latest
# slots 13783 rss 257108
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment