Skip to content

Instantly share code, notes, and snippets.

@databyte
Created May 4, 2012 21:00
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 databyte/2597700 to your computer and use it in GitHub Desktop.
Save databyte/2597700 to your computer and use it in GitHub Desktop.
rsolr memory leak test
require 'rsolr'
require 'thread'
require 'optparse'
require 'ruby-debug'
require 'ruby-prof'
module Allocation
def self.count
GC.disable
before = ObjectSpace.count_objects
yield
after = ObjectSpace.count_objects
after.each { |k,v| after[k] = v - before[k] }
GC.enable
# GC.start
# gc_after = ObjectSpace.count_objects
# gc_after.each { |k,v| gc_after[k] = v - before[k] }
# puts "after GC: #{gc_after.inspect}"
after
end
end
$opts = {}
OptionParser.new do |o|
o.on("-u","--url URL","url") do |u|
$opts[:url] = u
end
o.parse!
end
# RubyProf.start
foo = "this is a long string " * 10
docs = []
$q = Queue.new
5_000.times do |i|
doc = {}
doc["id"] = "Test #{i}"
doc["id_is"] = i
doc["ingredient_list_sms"] = [foo]
doc["tag_sms"] = [Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")]
docs << doc
if i % 25 == 0 && i != 0
puts "adding #{i}"
$q << docs
docs = []
end
end
solr = RSolr.connect(:url => $opts[:url])
p ObjectSpace.count_objects
puts "-" * 50
while $q.length > 0 do
item = $q.pop
if item
begin
puts "thread #{Thread.current.inspect} adding #{item.first["id"]} to #{item.last["id"]}"
p(Allocation.count do
solr.add item
end)
rescue Exception => e
puts "problem on #{Thread.current.inspect}: #{e}"
end
end
end
puts "-" * 50
p ObjectSpace.count_objects
# result = RubyProf.stop
# printer = RubyProf::FlatPrinter.new(result)
# printer.print(STDOUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment