You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Alexander N <wn...@interniche.de> on 2011/07/21 16:27:52 UTC

MessageServlet and Memory-/CPU-Consumption

Hi,

I'm running ActiveMQ 5.3.2 as a server under Debian 5.0
and I'm using the REST-Servlet of the demo-webapp 
(MessageServlet) to post messsages to one queue.

The setup is quite out-of-the-box but it shows a strange
behavior when the amount of messages increases 
significantly.
When I'm sending 1 messages/sec, everything works fine.
But with 50 messages/sec the ActiveMQ-Server runs out
of threads or out of memory and in the same time consumes
an essential amount of cpu-time. I configured the JVM with
2Gb of Memory but still after a certain amount of time
(a few hours) out-of-memory-Exceptions occur (for ~50 
messages/sec).

So I've done some research (even bought the book "ActiveMQ in
Action") and came to the conclusion that this behavoir could
occur because of there is probably no pooling of connections 
done if the demo-webapp if is running outside a J2EE-environment.

So I tried to add a pooling connection factory to
activemq.xml (inspired by what is described in the book
on page 166) by adding the following beans to activemq.xml:

        <beans
            ...
              <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                  <property name="locations">
                     
<value>file:${activemq.base}/conf/credentials.properties</value>
                  </property>
              </bean>
             
        <bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://locahost:61616" />
        </bean>
      
        <bean id="pooledJmsConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory"
destroy-method="stop">
            <property name="connectionFactory" ref="jmsConnectionFactory" />
        </bean>
       
        <broker
            ...
        </broker>
        ...
        </beans>

This connection-pool I try to refernce in the web.xml of the
MessageServelet.
It looks like this:

        <web-app>
            ...
        <context-param>
            <param-name>org.apache.activemq.brokerURL</param-name>
            <param-value>tcp://localhost:61616</param-value>
            <description>The URL of the Message Broker to connect
to</description>
        </context-param>
   
        <context-param>
            <param-name>org.apache.activemq.embeddedBroker</param-name>
            <param-value>false</param-value>
            <description>Whether we should include an embedded broker or
not</description>
        </context-param>
       
        <context-param>
            <param-name>org.apache.activemq.connectionFactory</param-name>
            <param-value>pooledJmsConnectionFactory</param-value>
        </context-param>
        ...
        </web-app>

But that doesn't seem to do the pooling-job, at least it has no
effect on memory-consumption. Appearently I'm doing sth wrong
(or even substantally wrong ;) here.


Now I have 2 questions:

1. Can the lack of connection-pooling be the reason of the extensive
memory- and cpu-consumption of the the Message-Servlet on my
(very much default) ActiveMQ-installation ?

2. Is there a way to add connection-pooling to the demo-
webapp without deploying it in a J2EE-container?


Thanx in advance for any help!

--
View this message in context: http://activemq.2283324.n4.nabble.com/MessageServlet-and-Memory-CPU-Consumption-tp3683823p3683823.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: MessageServlet and Memory-/CPU-Consumption

Posted by Torsten Mielke <to...@fusesource.com>.
Regarding your questions:

1) Yes, without a pooled connection factory it is possible that you create a new JMS connection, session, producer/consumer for every new message. Creating these JMS resources is very expensive in terms of performance and CPU usage. 
There are some additional details given in this blog post: 
http://tmielke.blogspot.com/2009/12/using-spring-jms-template-for-sending.html

2) Certainly yes when using a pooled connection factory as you have already configured. 

I am not very familiar with configuring ActiveMQ in a web application, so I am not sure what's wrong in your config. 
However using a pooled connection factory is definitely recommended, in case you plan to use Spring JMS to send/receive messages.


Torsten Mielke
torsten@fusesource.com
tmielke@blogspot.com