The messages are persistent, so shouldn't this give the broker the option of
sending them to the store, thus freeing up memory? Only if the messages are
non-persistent does the broker have no choice but to keep them in-memory.

Saqib is right, you should only have to create one connection. Connections
are heavy-weight objects, opening and closing one for each send puts a lot
of strain on the system. Because you're sending to the same topic, you can
also get away with having to create just one session and publisher. 

Regards,
Joe 

 

srasul wrote:
> 
> Hi Phill,
> 
> from what i can see, you are sending persistant messages to a topic, this
> means that if no one is listening on that topic, your messages will he
> stored (aka held in memory) until someone listens on that topic. this
> would explain why you run out of memory. Essentially you experiencing the
> "slow consumer" issue: http://activemq.apache.org/slow-consumers.html
> 
> another issue might be that you are creating connections to activeMQ for
> each message. this may be an issue on windows machines (atleast i know
> this issue on WinXP) where it runs out of ports to assign for your
> connection. so your might be better off using one connection to send 5000
> messages atleast on Windows machines.
> 
> hope this helps,
> 
> Regards,
> 
> Saqib
> 
> 
> WHIRLYCOTT wrote:
>> 
>> I'm attaching a pretty straightforward example of some code that  
>> exhibits a problem that I'm having trouble fixing.  I'm hoping  
>> someone can either point out my error or at least help me diagnose  
>> the problem.  Basically, the code simply sends ~5000 messages to a  
>> broker.  Yes, it's not using a connection pool.  That doesn't seem to  
>> make any difference and I'm looking for the simplest possible  
>> example.  After about ~1300 messages, the client runs out of memory  
>> and dies (jvm default is 64Mb, iirc).
>> 
>> I've tested this with recent AMQ nightly builds or with 5.0.0.2-fuse  
>> and I get the same result in both cases.  In running this code, I'm  
>> also seeing several exceptions like this (maybe ~10 by the time I get  
>> the OOME):
>> 
>> [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] WARN   
>> org.apache.activemq.ActiveMQConnection  - Async exception with no  
>> exception listener: java.net.SocketException: Socket closed
>> 
>> Here's the offending code.  Any help would be super.
>> 
>> phil.
>> 
>> import javax.jms.Connection;
>> import javax.jms.DeliveryMode;
>> import javax.jms.JMSException;
>> import javax.jms.MapMessage;
>> import javax.jms.MessageProducer;
>> import javax.jms.Session;
>> import javax.jms.Topic;
>> 
>> import org.apache.activemq.ActiveMQConnectionFactory;
>> import org.apache.log4j.Logger;
>> 
>> public class ActiveMQClientDyingExample {
>> 
>>      private static final Logger log = Logger.getLogger 
>> (ActiveMQClientDyingExample.class);
>> 
>>      public static void main(final String args[]) {
>> 
>>              final String url = "tcp://localhost:61616";
>>              final String topicName = "test/foo";
>> 
>>              log.debug("Initializing pooled connection factory for JMS to 
>> URL: "  
>> + url);
>>              final ActiveMQConnectionFactory normalFactory = new  
>> ActiveMQConnectionFactory();
>>              normalFactory.setBrokerURL(url);
>> 
>>              for (int i = 0; i < 5000; i++) {
>>                      
>>                      if (i % 100 ==0)
>>                              log.debug(i);
>> 
>>                      Connection conn = null;
>>                      try {
>> 
>>                              conn = normalFactory.createConnection();
>>                              final Session session = 
>> conn.createSession(false,  
>> Session.AUTO_ACKNOWLEDGE);
>>                              final Topic topic = 
>> session.createTopic(topicName);
>>                              final MessageProducer producer = 
>> session.createProducer(topic);
>>                              
>> producer.setDeliveryMode(DeliveryMode.PERSISTENT);
>> 
>>                              final MapMessage m = session.createMapMessage();
>>                              m.setInt("hey", i);
>> 
>>                              producer.send(m);
>> 
>>                      } catch (JMSException e) {
>>                              log.warn(e.getMessage(), e);
>>                      } finally {
>>                              if (conn != null)
>>                                      try {
>>                                              conn.close();
>>                                      } catch (JMSException e) {
>>                                              log.warn(e.getMessage(), e);
>>                                      }
>>                      }
>> 
>>              }
>>      }
>> 
>> }
>> 
>> 
>> 
>> --
>>                                     Whirlycott
>>                                     Philip Jacob
>>                                     [EMAIL PROTECTED]
>>                                     http://www.whirlycott.com/phil/
>> 
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Crashing-an-AMQ-producer-in-%7E12-seconds-tf4545474s2354.html#a12978205
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to