You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by "Pieper, Aaron (SAIC)" <Pi...@Pragmatics.com> on 2008/08/05 00:26:36 UTC

Memory leak in broker when subscribing to a topic using TCP connector + noLocal?

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<String, Object> map = new HashMap<String,
Object>();

                  map.put("1", new byte[1000000]);

                  template.convertAndSend(topic, map);

                  sendCount++;

                  Thread.sleep(1);

            }

      }

}


Re: Memory leak in broker when subscribing to a topic using TCP connector + noLocal?

Posted by Joe Fernandez <jo...@ttmsolutions.com>.
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<String, Object> map = new HashMap<String,
> 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.


Re: Memory leak in broker when subscribing to a topic using TCP connector + noLocal?

Posted by Jean-Yves LEBLEU <jl...@gmail.com>.
Hello all,

I don't know if it is the same case but even if you remove the listener and
set local to false, you get a java.lang.OutOfMemoryError: Java heap space

Here is the trace

Memory Usage:    0    Memory Percent:    0    Send count:    0    Memory:
 5177344
Memory Usage:    0    Memory Percent:    0    Send count:    64    Memory:
 21839872
Memory Usage:    0    Memory Percent:    0    Send count:    160
 Memory:    36556800
Memory Usage:    0    Memory Percent:    0    Send count:    255
 Memory:    66650112
Memory Usage:    0    Memory Percent:    0    Send count:    360
 Memory:    66650112
Memory Usage:    0    Memory Percent:    0    Send count:    474
 Memory:    66650112
Memory Usage:    0    Memory Percent:    0    Send count:    542
 Memory:    66650112
Memory Usage:    0    Memory Percent:    0    Send count:    578
 Memory:    66650112
Exception in thread "ActiveMQ Transport Server Thread Handler:
tcp://localhost:8192" java.lang.OutOfMemoryError: Java heap space
    at
org.apache.activemq.openwire.OpenWireFormat.<init>(OpenWireFormat.java:60)
    at
org.apache.activemq.openwire.OpenWireFormat.<init>(OpenWireFormat.java:66)
    at
org.apache.activemq.openwire.OpenWireFormatFactory.createWireFormat(OpenWireFormatFactory.java:62)
    at
org.apache.activemq.transport.tcp.TcpTransportServer.handleSocket(TcpTransportServer.java:336)
    at
org.apache.activemq.transport.tcp.TcpTransportServer$1.run(TcpTransportServer.java:283)
    at java.lang.Thread.run(Thread.java:619)
Memory Usage:    0    Memory Percent:    0    Send count:    586
 Memory:    66650112
Memory Usage:    0    Memory Percent:    0    Send count:    586
 Memory:    66650112


Here is the test case :

package com.alcatel.proserv.testamqmem;

import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

import javax.jms.Connection;
import javax.jms.MessageConsumer;
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();
    private Runtime runtime;

    public static void main(String[] args) throws Exception {
        new BrokerMemoryLeak().run();
    }

    private void run() throws Exception {
        runtime = Runtime.getRuntime();
        broker.setPersistent(false);
        broker.addConnector("tcp://localhost:8192");
        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);

        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");

buf.append("Memory:\t").append(runtime.totalMemory()).append("\t");
                System.out.println(buf);
            }

        };

        new Timer().schedule(statusTask, 0, 1000);
        JmsTemplate template = new JmsTemplate();
        template.setConnectionFactory(connectionFactory);
        template.afterPropertiesSet();

        while (true) {

            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("1", new byte[100000]);
            template.convertAndSend(topic, map);
            sendCount++;
            Thread.sleep(1);
        }

    }

}


On Fri, Aug 15, 2008 at 4:08 PM, Hiram Chirino <hi...@hiramchirino.com>wrote:

> I opened issue https://issues.apache.org/activemq/browse/AMQ-1889
> and have committed a fix.  Thanks for the report.. Still looking
> forward for your test case contribution so that the test suite can
> catch this error in the future.
>
> On Fri, Aug 15, 2008 at 8:35 AM, Hiram Chirino <hi...@hiramchirino.com>
> wrote:
> > I just tried out your attached test case and yeah it looks like a
> > problem.  Could you shoot us back an email letting us know that you
> > are willing to contribute the test case to the ASF under the ASL 2.0
> > license so we can include parts of it in test suite?
> >
> > On Mon, Aug 4, 2008 at 6:26 PM, Pieper, Aaron (SAIC)
> > <Pi...@pragmatics.com> 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<String, Object> map = new HashMap<String,
> >> Object>();
> >>
> >>                  map.put("1", new byte[1000000]);
> >>
> >>                  template.convertAndSend(topic, map);
> >>
> >>                  sendCount++;
> >>
> >>                  Thread.sleep(1);
> >>
> >>            }
> >>
> >>      }
> >>
> >> }
> >>
> >>
> >
> >
> >
> > --
> > Regards,
> > Hiram
> >
> > Blog: http://hiramchirino.com
> >
> > Open Source SOA
> > http://open.iona.com
> >
>
>
>
> --
> Regards,
> Hiram
>
> Blog: http://hiramchirino.com
>
> Open Source SOA
> http://open.iona.com
>

Re: Memory leak in broker when subscribing to a topic using TCP connector + noLocal?

Posted by Rob Davies <ra...@gmail.com>.
Yes please - submit the test case - and when attaching it to the jira  
issue - click the grant to apache check box

thanks,

Rob
On 7 Oct 2008, at 22:36, xnbuslynsobm wrote:

>
>
> Hiram Chirino wrote:
>>
>> I opened issue https://issues.apache.org/activemq/browse/AMQ-1889
>> and have committed a fix.  Thanks for the report.. Still looking
>> forward for your test case contribution so that the test suite can
>> catch this error in the future.
>>
>
> Sorry for the late reply. Sure, you have my permission to do  
> whatever you
> want with the test case I submitted. Do you need me to submit this  
> as a
> traditional JUnit test case?
>
> (This is Aaron Pieper. I have created a new account because Nabble  
> won't
> e-mail me my password.)
>
> - Aaron
> -- 
> View this message in context: http://www.nabble.com/Memory-leak-in-broker-when-subscribing-to-a-topic-using-TCP-connector-%2B-noLocal--tp18821110p19867850.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>


Re: Memory leak in broker when subscribing to a topic using TCP connector + noLocal?

Posted by xnbuslynsobm <xn...@mailinator.com>.

Hiram Chirino wrote:
> 
> I opened issue https://issues.apache.org/activemq/browse/AMQ-1889
> and have committed a fix.  Thanks for the report.. Still looking
> forward for your test case contribution so that the test suite can
> catch this error in the future.
> 

Sorry for the late reply. Sure, you have my permission to do whatever you
want with the test case I submitted. Do you need me to submit this as a
traditional JUnit test case?

(This is Aaron Pieper. I have created a new account because Nabble won't
e-mail me my password.)

- Aaron
-- 
View this message in context: http://www.nabble.com/Memory-leak-in-broker-when-subscribing-to-a-topic-using-TCP-connector-%2B-noLocal--tp18821110p19867850.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Memory leak in broker when subscribing to a topic using TCP connector + noLocal?

Posted by Hiram Chirino <hi...@hiramchirino.com>.
I opened issue https://issues.apache.org/activemq/browse/AMQ-1889
and have committed a fix.  Thanks for the report.. Still looking
forward for your test case contribution so that the test suite can
catch this error in the future.

On Fri, Aug 15, 2008 at 8:35 AM, Hiram Chirino <hi...@hiramchirino.com> wrote:
> I just tried out your attached test case and yeah it looks like a
> problem.  Could you shoot us back an email letting us know that you
> are willing to contribute the test case to the ASF under the ASL 2.0
> license so we can include parts of it in test suite?
>
> On Mon, Aug 4, 2008 at 6:26 PM, Pieper, Aaron (SAIC)
> <Pi...@pragmatics.com> 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<String, Object> map = new HashMap<String,
>> Object>();
>>
>>                  map.put("1", new byte[1000000]);
>>
>>                  template.convertAndSend(topic, map);
>>
>>                  sendCount++;
>>
>>                  Thread.sleep(1);
>>
>>            }
>>
>>      }
>>
>> }
>>
>>
>
>
>
> --
> Regards,
> Hiram
>
> Blog: http://hiramchirino.com
>
> Open Source SOA
> http://open.iona.com
>



-- 
Regards,
Hiram

Blog: http://hiramchirino.com

Open Source SOA
http://open.iona.com

Re: Memory leak in broker when subscribing to a topic using TCP connector + noLocal?

Posted by Hiram Chirino <hi...@hiramchirino.com>.
I just tried out your attached test case and yeah it looks like a
problem.  Could you shoot us back an email letting us know that you
are willing to contribute the test case to the ASF under the ASL 2.0
license so we can include parts of it in test suite?

On Mon, Aug 4, 2008 at 6:26 PM, Pieper, Aaron (SAIC)
<Pi...@pragmatics.com> 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<String, Object> map = new HashMap<String,
> Object>();
>
>                  map.put("1", new byte[1000000]);
>
>                  template.convertAndSend(topic, map);
>
>                  sendCount++;
>
>                  Thread.sleep(1);
>
>            }
>
>      }
>
> }
>
>



-- 
Regards,
Hiram

Blog: http://hiramchirino.com

Open Source SOA
http://open.iona.com