Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 21133 invoked from network); 5 Aug 2008 02:59:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Aug 2008 02:59:19 -0000 Received: (qmail 20126 invoked by uid 500); 5 Aug 2008 02:59:17 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 20107 invoked by uid 500); 5 Aug 2008 02:59:17 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 20096 invoked by uid 99); 5 Aug 2008 02:59:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Aug 2008 19:59:17 -0700 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Aug 2008 02:58:20 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1KQCl3-0002Qr-On for users@activemq.apache.org; Mon, 04 Aug 2008 19:58:45 -0700 Message-ID: <18823693.post@talk.nabble.com> Date: Mon, 4 Aug 2008 19:58:45 -0700 (PDT) From: Joe Fernandez To: users@activemq.apache.org Subject: Re: Memory leak in broker when subscribing to a topic using TCP connector + noLocal? In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: joe.fernandez@ttmsolutions.com References: X-Virus-Checked: Checked by ClamAV on apache.org Do you get the same sort of behavior if you point your pub/sub client to an external broker? Joe www.ttmsolutions.com Aaron Pieper wrote: > > I'm encountering what appears to be a memory leak in the BrokerService. > The symptom is that the BrokerService's memory usage increases with each > message that is sent to a topic, as though each message is being stored > permanently in memory. > > > > I've included an example which demonstrates the issue. If you run the > included BrokerMemoryLeak.java, you should see the following output: > > > > Memory Usage: 0 Memory Percent: 0 Send count: 0 > > Memory Usage: 16016576 Memory Percent: 23 Send count: 16 > > Memory Usage: 38039368 Memory Percent: 56 Send count: 38 > > Memory Usage: 61063196 Memory Percent: 90 Send count: 61 > > Memory Usage: 68070448 Memory Percent: 101 Send count: 68 > > Memory Usage: 68070448 Memory Percent: 101 Send count: 68 > > Memory Usage: 68070448 Memory Percent: 101 Send count: 68 > > > > BrokerService's memory usage climbs steadily until the memory percent > hits 100. Then, messages stop being sent. There are several ways to make > the bug stop happening: > > * Switch from using a Topic to a Queue > > * Switch the Broker address to 'vm://foo', so it's not using TCP > > * Set the third argument in the 'createConsumer' call to false. (the > noLocal argument) > > * Don't register the MessageListener > > > > I've witnessed this behavior both with ActiveMQ 5.1.0 and the > 5.2-SNAPSHOT version available as of August 4, 2008. I'm using Spring > 2.5.4. Since two-way traffic isn't an issue for this application, I can > fix the issue by setting 'noLocal' to false. However, I wasn't sure > whether I should submit a JIRA tracker for this, or whether I'm doing > something wrong. > > > > Thanks, > > > > - Aaron Pieper > > > > -------------------------------- > > > > import java.util.HashMap; > > import java.util.Timer; > > import java.util.TimerTask; > > > > import javax.jms.Connection; > > import javax.jms.Message; > > import javax.jms.MessageConsumer; > > import javax.jms.MessageListener; > > import javax.jms.Session; > > import javax.jms.Topic; > > > > import org.apache.activemq.ActiveMQConnectionFactory; > > import org.apache.activemq.ActiveMQSession; > > import org.apache.activemq.broker.BrokerService; > > import org.apache.activemq.usage.MemoryUsage; > > import org.springframework.jms.core.JmsTemplate; > > > > public class BrokerMemoryLeak { > > private int sendCount; > > private BrokerService broker = new BrokerService(); > > > > public static void main(String[] args) throws Exception { > > new BrokerMemoryLeak().run(); > > } > > > > private void run() throws Exception { > > broker.addConnector("tcp://localhost:8192"); > > broker.setPersistent(false); > > broker.start(); > > > > ActiveMQConnectionFactory connectionFactory = (new > ActiveMQConnectionFactory("tcp://localhost:8192")); > > Connection connection = > connectionFactory.createConnection(); > > connection.start(); > > > > ActiveMQSession session = (ActiveMQSession) > connection.createSession(false, Session.AUTO_ACKNOWLEDGE); > > Topic topic = session.createTopic("foo"); > > MessageConsumer messageConsumer = > session.createConsumer(topic, null, true); > > > > messageConsumer.setMessageListener(new MessageListener() { > > public void onMessage(Message message) {} > > }); > > > > TimerTask statusTask = new TimerTask() { > > @Override > > public void run() { > > StringBuffer buf = new StringBuffer(); > > MemoryUsage memoryUsage = > broker.getSystemUsage().getMemoryUsage(); > > buf.append("Memory > Usage:\t").append(memoryUsage.getUsage()).append("\t"); > > buf.append("Memory > Percent:\t").append(memoryUsage.getPercentUsage()).append("\t"); > > buf.append("Send > count:\t").append(sendCount).append("\t"); > > System.out.println(buf); > > } > > }; > > > > new Timer().schedule(statusTask, 0, 1000); > > > > JmsTemplate template = new JmsTemplate(); > > template.setConnectionFactory(connectionFactory); > > template.afterPropertiesSet(); > > > > while (true) { > > HashMap map = new HashMap Object>(); > > map.put("1", new byte[1000000]); > > template.convertAndSend(topic, map); > > sendCount++; > > Thread.sleep(1); > > } > > } > > } > > > -- View this message in context: http://www.nabble.com/Memory-leak-in-broker-when-subscribing-to-a-topic-using-TCP-connector-%2B-noLocal--tp18821110p18823693.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.