-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.7.0
-
Component/s: None
-
Environment:CentOS 5.4, ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Consider the following Ruby code:
require 'mongo'
DB = Mongo::Connection.new('localhost', 27017)['test_db']
@collection = DB['test_collection']
code = -> { @collection.find(
{"Name" => "aaron.symplicity.com"}).each
{|d| d} }
high = 0
pid = 0
size = 0
loop do
th = Thread.new do
code.call
pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#
"`.chomp.split(/\s+/).map
{|s| s.strip.to_i} if size > high
puts "New high: #
"
high = size
p "Threads: #{ObjectSpace.each_object(Thread) {}}"
p "Strings: #{ObjectSpace.each_object(String) {}}"
end
end
th.join
end
If you look at the output of this code, Thread objects are never garbage collected after the thread does a query using the MongoDB driver. If you comment out "code.call", thread objects are garbage collected and usage stays down. Try inserting a few objects with string values into the test db/collection and running the above code, and you'll see a steady increase in string objects.
This pretty much makes Mongo + EventMachine.defer (or any thread pool) a no go.
Also a note, this does not happen with Fiber's – only Threads.