You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Thomas Lockney <tl...@gmail.com> on 2010/06/03 20:53:41 UTC

Problems with lingering ActiveMQTempQueue objects

I'm seeing a problem in a production application where it appears that
instances of ActiveMQTempQueue are not going away. What's happening is that
our apps send messages intended for remote agents. The agents speak to our
servers through a servlet frontend, so essentially we're proxying ActiveMQ
(it's a bit more complicated than that, but hopefully that gives the
essential picture).

I'm using temporary response queues as per the JMS spec and attaching these
to the message using setJMSReplyTo(responseQueue). The calling code then
sits and waits for the response or times out and then closes the connection.
On servlet side, these messages come in from ActiveMQ and when the
appropriate agent connects, get sent down. The servlet-side code has a local
map of the messages so that when the response comes back from the agent, it
can reference the response queue and send back the data. At this point, the
object which holds the reference to the response queue is removed from the
map.

Over the course of a few days, we end up seeing all the heap space on the
servlet-side JVMs disappearing. I've started taking hourly heap dumps and
I'm seeing the number of ActiveMQTempQueue objects quickly increasing. In
one case right now, I'm seeing one of our JVMs has nearly 2 million of these
objects! My initial thought on seeing this was that the objects which
referenced them were not getting removed correctly from the map and
therefore were not getting GCed. But there are only about 3000 of those in
the heap right now -- that's about a typical number we'd expect to see given
the usage of our system.

I've been reading through old threads on this list for possible answers, but
it looks like most of the solutions to past problems have already been
rolled into the source. We're using ActiveMQ 5.2.0 for what it's worth. I've
tried manually deleting the temp queues after sending back the response, but
that doesn't appear to effect anything. I've also tried modifying the
ActiveMQ source so that setAutoCreateDestinations(false) is called in the
constructor of TempQueueRegion, based on info from this thread:
http://old.nabble.com/Problems-with-prefetch-and-TemporaryQueues-tt27130529.html#a27130529

I'm trying to figure out if there's anything else I might be missing. I'm
tempted to rework all this to use a single response topic with message
selectors using a unique response ID, but I've had performance problems in
the past with selectors, so I'm hesitant to go that route if there might be
an obvious solution here that I'm missing. 

Any ideas?

~thomas
-- 
View this message in context: http://old.nabble.com/Problems-with-lingering-ActiveMQTempQueue-objects-tp28771545p28771545.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Problems with lingering ActiveMQTempQueue objects

Posted by Thomas Lockney <tl...@gmail.com>.
> > I'm using temporary response queues as per the JMS spec and attaching
these
> > to the message using setJMSReplyTo(responseQueue). The calling code then
> > sits and waits for the response or times out and then closes the
> connection.
> 
> Sorry, did I understand correctly and you create a new temporary queue
> per every request?

Not exactly. For any messages sent by the backend service that expect a
reply, we create a new temp queue and attach it to the source message. Since
the temporary queue objects are supposed to be closed, as defined by the JMS
API, when the original connection is closed, creating a new temp queue per
source message seemed the right way to do it. In fact, all of the docs and
discussions I read implied that was the way you *must* do it for reliable
behavior.

> We use one or few temporary (or even normal) queues, attach them to
> requests using setJMSReplyTo(responseQueue) and match replies by
> correlation Id. Therefore, a response queue is (re-)used for multiple
> requests, normally until connection to ActiveMQ broker is broken for
> some reason.

Right, that's the approach I'm considering if I can't figure out why these
objects are hanging around. I might give it a go anyway, since we're in
desperate need of a fix here. Of course, it's a balancing act -- this code
is already in production and was working fine until we started getting heavy
usage on this new system. So the ideal fix is one that changes the least
amount of code, but perhaps it will require a more invasive fix to truly
address the underlying issue.

> Creation of any queue or topic is a sync request to broker. Creation
> of consumer is another sync request to broker. Same for producers and
> sessions. So, for optimal performance you should cache all these
> objects and reuse them for as many requests as possible.

Actually, that touches on the other issues (which actually clued us into the
source of the problem in the first place) -- since all these
ActiveMQTempQueue objects are hanging around and not getting cleaned up,
they are eating up network bandwidth as they communicate with the ActiveMQ
brokers. It isn't high enough to cause us any heartache, yet, but it made
the problem obvious.
-- 
View this message in context: http://old.nabble.com/Problems-with-lingering-ActiveMQTempQueue-objects-tp28771545p28771990.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Problems with lingering ActiveMQTempQueue objects

Posted by Ivan Pechorin <iv...@gmail.com>.
> I'm using temporary response queues as per the JMS spec and attaching these
> to the message using setJMSReplyTo(responseQueue). The calling code then
> sits and waits for the response or times out and then closes the connection.

Sorry, did I understand correctly and you create a new temporary queue
per every request?

> I'm
> tempted to rework all this to use a single response topic with message
> selectors using a unique response ID, but I've had performance problems in
> the past with selectors, so I'm hesitant to go that route if there might be
> an obvious solution here that I'm missing.

We use one or few temporary (or even normal) queues, attach them to
requests using setJMSReplyTo(responseQueue) and match replies by
correlation Id. Therefore, a response queue is (re-)used for multiple
requests, normally until connection to ActiveMQ broker is broken for
some reason.

Creation of any queue or topic is a sync request to broker. Creation
of consumer is another sync request to broker. Same for producers and
sessions. So, for optimal performance you should cache all these
objects and reuse them for as many requests as possible.

P.S. Sorry if I misunderstood you and wrote something very obvious and
irrelevant to your problem :)

Best regards, Ivan