[zeromq-dev] Ruby GC
Morten Møller Riis
mortenmoellerriis at gmail.com
Tue Dec 20 22:03:03 CET 2011
Hi Guys
I am having a problem that is driving me crazy.
It seems to me that the ruby garbage collector and zeromq might not be the best of friends.
I have an application that uses ZMQ where something like this happens:
class Client
def self.listen
@socket = ZMQ::Context.new.socket(ZMQ::UPSTREAM)
@socket.bind("tcp://#{IP}:#{MINION_PORT}")
while(true)
msg = @socket.recv()
# do something with the message
end
end
end
Depending on the Ruby version (I've tried MRI 1.8.7, 1.9.2p290, 1.9.3p0, REE, afaik the garbage collectors are actually different except 1.9.2&1.9.3 since it was rewritten to be lazy and REE does kind of the same thing I think) I get a different result. But not much. It seems that it will only accept a number of messages before hanging.
The thing is, if I disable the GC like this:
class Client
def self.listen
@socket = ZMQ::Context.new.socket(ZMQ::UPSTREAM)
@socket.bind("tcp://#{IP}:#{MINION_PORT}")
GC.disable
while(true)
msg = @socket.recv()
# do something with the message
end
end
end
It works. The Ruby process will of course grow infinitely large though.
I've searched around but haven't been able to find any similar results. I actually have another small zmq service running that never ran into this problem, so I am thinking it might be something new for 2.1.x..?
Any help is highly appreciated!
Best regards
Morten Møller Riis
More information about the zeromq-dev
mailing list