You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Fabrice Landrodie <fa...@alcatel-lucent.fr> on 2008/03/07 13:29:07 UTC

Servicemix-bean MemoryLeak

Hello,

I am facing some memoryleak problems when using MessageExchange and
servicemix-bean.

My use case is as followed :

http client --> BC Http Su --> smx-bean Su --> smx-bean Su

The request send by http client is routed to the first smx-bean Su. In
onMessageExchange() function, I create a new MessageExchange that I sent to
the second smx-bean Su using sendSync() in InOut mep. The answer is the
placed into the Out of the first Exchange and send back to the BC http.

It works well but the problem is that if I send a lot of request, memory
increases but never decrease at the end of the treatment. If I set a big
size for the xml body of the request, the memory increases faster and an
OutOfMemory exception is raised. So it seems the memory leak is relative to
the size of the message.

I think it could be a problem of MessageExchance that are never dereferenced
so that the garbage collector does not free them.

I use a profiler to try to analyze where the memory is leak, and it seems
this is in a lot of int[] and char[] objects ....


Can someone help me on this problem ? Maybe, I do not code the good way for
sending message from a bean to another one.

Thank you for your help,
Fabrice

--------------------------------------------------------------------------------------
Here is the code of the first smx-bean SU with the onMessageExchange :

public class MyBean implements MessageExchangeListener {
	
	private static ServiceMixClient client = null;
	
	@Resource
	private DeliveryChannel channel;
	@Resource
	private ComponentContext context;

	public void onMessageExchange (MessageExchange exchange ) throws
MessagingException {
		
		if ( client == null ) {
			client = new ServiceMixClientFacade(context);
		}
	
		if (exchange.getStatus() == ExchangeStatus.ACTIVE) {

			if (exchange instanceof InOut == true) {

				Destination destination;
				destination
client.createDestination("endpoint:http://myNameSpace/MyService/MyEndpoint");
                                // Create New MessageExchange
				InOut syncExchange = destination.createInOutExchange();
				QName qOperation = new QName("myOp");
				exchange.setOperation(qOperation);

                                // Get object of In Message
				NormalizedMessage request = syncExchange.getInMessage();
                                // Set the content of new In exchange with
th In coming from our caller
				request.setContent(exchange.getMessage("in").getContent());

                                // Send the new exchange and wait for the
anwer
				client.sendSync(syncExchange);
				
                                // Set the out of the syncExchange into the
out of the current exchange and send back the current exchange
				MessageUtil.transferToOut(syncExchange.getMessage("out"), exchange);
				channel.send(exchange);
					
			}
	}
}
-- 
View this message in context: http://www.nabble.com/Servicemix-bean-MemoryLeak-tp15891209s12049p15891209.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Servicemix-bean MemoryLeak

Posted by pratibhaG <pr...@in2m.com>.
I have following code:

ServiceMixClient client = null;
    
    
DeliveryChannel channel;
    
ComponentContext context; 
    		
        if ( client == null ) {
            client = new ServiceMixClientFacade(context);
        }
        
        Destination
destination=client.createDestination("service:http://servicemix.in2m.com/samples/http/JMSService");
         
        InOnly syncExchange = destination.createInOnlyExchange();
       
        NormalizedMessage request = syncExchange.getInMessage();
       
        request.setContent(exchange.getMessage("in").getContent());
       
        client.sendSync(syncExchange);
        client.done(syncExchange);
        
    	
It gives me NullPointerException at line 
InOnly syncExchange = destination.createInOnlyExchange();

I tried printing destination object and it is not null.

Can anybody tell me what is wrong?

Pratibha
-- 
View this message in context: http://www.nabble.com/Servicemix-bean-MemoryLeak-tp15891209p17535149.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Servicemix-bean MemoryLeak

Posted by Fabien BIDET <fa...@alcatel-lucent.fr>.
Hello,

I have the problem of memory leak, like Fabrice Landrodie, when a lot of
requests are sent to my 
Service Unit.

Let me show you the code of the operation used:


@Operation(name = "test2")
public void test2(MessageExchange exchange) throws MessagingException {
	String res = "<testResponse><NanoSec>10</NanoSec></testResponse>";
	if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
		NormalizedMessage message = null;
		if (exchange instanceof InOut == true) {
			message = exchange.createMessage();
			message.setContent(new StreamSource(new StringReader(res)));
			MessageUtil.transferToOut(message, exchange);
		} else if (exchange instanceof InOnly == true) {
			exchange.setStatus(ExchangeStatus.DONE);
		}
	}
	channel.send(exchange);
}

I am using a client how send a lot of requests to this ServiceUnit and I can
see a lot of "org.apache.xerces.dom.DeferredDocumentImpl" objects created
but never free. I think the MessageExchange is still ACTIVE (so streams "in"
and "out" are never closed) but I don't know how and  where I can modify the
MessageExchange's status to ExchangeStatus.DONE.

I tried your solution:

@Operation(name = "test2")
public void test2(MessageExchange exchange) throws MessagingException {
	...
	exchange.setStatus(ExchangeStatus.DONE);
	channel.send(exchange);
}

but this error occured:

ERROR - [servicemix-http]              - Servlet.service() for servlet
servicemix-http threw exception
javax.jbi.messaging.MessagingException: illegal exchange status: done
        at
org.apache.servicemix.jbi.messaging.MessageExchangeImpl.handleSend(MessageExchangeImpl.java:626)
        at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.doSend(DeliveryChannelImpl.java:385)
        at
org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.send(DeliveryChannelImpl.java:431)
        at
org.apache.servicemix.common.EndpointDeliveryChannel.send(EndpointDeliveryChannel.java:79)
        at
org.apache.servicemix.bean.BeanEndpoint$PojoChannel.send(BeanEndpoint.java:568)
        at MyClass.test2(MySo1.java:299)
		at ...
		

Do you have another idea?

Thanks

Regards,
Fabien BIDET	


gnodet wrote:
> 
> There's no real difference. Such thing is mandatory when using
> directly the DeliveryChannel too.
> If you don't, you may end up with threads locked forever or memory leaks.
> With the delivery channel, you'd do:
>    exchange.setStatus(ExchangeStatus.DONE);
>    channel.send(exchange);
> Btw, that's exactly what the client does.
> 
> 

-- 
View this message in context: http://www.nabble.com/Servicemix-bean-MemoryLeak-tp15891209p17213172.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Servicemix-bean MemoryLeak

Posted by Guillaume Nodet <gn...@gmail.com>.
There's no real difference. Such thing is mandatory when using
directly the DeliveryChannel too.
If you don't, you may end up with threads locked forever or memory leaks.
With the delivery channel, you'd do:
   exchange.setStatus(ExchangeStatus.DONE);
   channel.send(exchange);
Btw, that's exactly what the client does.

On Mon, Mar 10, 2008 at 9:57 AM, Fabrice Landrodie
<fa...@alcatel-lucent.fr> wrote:
>
>  Thank you very much Guillaume.
>  It works well now.
>
>  I was not aware that the behaviour and the way to code message exchange is a
>  bit different when unsing ServiceMixClient object or directly the
>  DeliveryChannel object.
>
>  Regards,
>  Fabrice
>
>
>
>
>
>  gnodet wrote:
>  >
>  > I think you forgot to set and send the DONE status at the end of your
>  > processing,
>  >       MessageUtil.transferToOut(syncExchange.getMessage("out"), exchange);
>  >       channel.send(exchange);
>  >       client.done(syncExchange);
>  >
>  > On Fri, Mar 7, 2008 at 1:29 PM, Fabrice Landrodie
>  > <fa...@alcatel-lucent.fr> wrote:
>  >>
>  >>  Hello,
>  >>
>  >>  I am facing some memoryleak problems when using MessageExchange and
>  >>  servicemix-bean.
>  >>
>  >>  My use case is as followed :
>  >>
>  >>  http client --> BC Http Su --> smx-bean Su --> smx-bean Su
>  >>
>  >>  The request send by http client is routed to the first smx-bean Su. In
>  >>  onMessageExchange() function, I create a new MessageExchange that I sent
>  >> to
>  >>  the second smx-bean Su using sendSync() in InOut mep. The answer is the
>  >>  placed into the Out of the first Exchange and send back to the BC http.
>  >>
>  >>  It works well but the problem is that if I send a lot of request, memory
>  >>  increases but never decrease at the end of the treatment. If I set a big
>  >>  size for the xml body of the request, the memory increases faster and an
>  >>  OutOfMemory exception is raised. So it seems the memory leak is relative
>  >> to
>  >>  the size of the message.
>  >>
>  >>  I think it could be a problem of MessageExchance that are never
>  >> dereferenced
>  >>  so that the garbage collector does not free them.
>  >>
>  >>  I use a profiler to try to analyze where the memory is leak, and it
>  >> seems
>  >>  this is in a lot of int[] and char[] objects ....
>  >>
>  >>
>  >>  Can someone help me on this problem ? Maybe, I do not code the good way
>  >> for
>  >>  sending message from a bean to another one.
>  >>
>  >>  Thank you for your help,
>  >>  Fabrice
>  >>
>  >>
>  >> --------------------------------------------------------------------------------------
>  >>  Here is the code of the first smx-bean SU with the onMessageExchange :
>  >>
>  >>  public class MyBean implements MessageExchangeListener {
>  >>
>  >>         private static ServiceMixClient client = null;
>  >>
>  >>         @Resource
>  >>         private DeliveryChannel channel;
>  >>         @Resource
>  >>         private ComponentContext context;
>  >>
>  >>         public void onMessageExchange (MessageExchange exchange ) throws
>  >>  MessagingException {
>  >>
>  >>                 if ( client == null ) {
>  >>                         client = new ServiceMixClientFacade(context);
>  >>                 }
>  >>
>  >>                 if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
>  >>
>  >>                         if (exchange instanceof InOut == true) {
>  >>
>  >>                                 Destination destination;
>  >>                                 destination
>  >>
>  >> client.createDestination("endpoint:http://myNameSpace/MyService/MyEndpoint");
>  >>                                 // Create New MessageExchange
>  >>                                 InOut syncExchange =
>  >> destination.createInOutExchange();
>  >>                                 QName qOperation = new QName("myOp");
>  >>                                 exchange.setOperation(qOperation);
>  >>
>  >>                                 // Get object of In Message
>  >>                                 NormalizedMessage request =
>  >> syncExchange.getInMessage();
>  >>                                 // Set the content of new In exchange
>  >> with
>  >>  th In coming from our caller
>  >>
>  >> request.setContent(exchange.getMessage("in").getContent());
>  >>
>  >>                                 // Send the new exchange and wait for the
>  >>  anwer
>  >>                                 client.sendSync(syncExchange);
>  >>
>  >>                                 // Set the out of the syncExchange into
>  >> the
>  >>  out of the current exchange and send back the current exchange
>  >>
>  >> MessageUtil.transferToOut(syncExchange.getMessage("out"), exchange);
>  >>                                 channel.send(exchange);
>  >>
>  >>                         }
>  >>         }
>  >>  }
>  >>  --
>  >>  View this message in context:
>  >> http://www.nabble.com/Servicemix-bean-MemoryLeak-tp15891209s12049p15891209.html
>  >>  Sent from the ServiceMix - User mailing list archive at Nabble.com.
>  >>
>  >>
>  >
>  >
>  >
>  > --
>  > Cheers,
>  > Guillaume Nodet
>  > ------------------------
>  > Blog: http://gnodet.blogspot.com/
>  >
>  >
>
>  --
>  View this message in context: http://www.nabble.com/Servicemix-bean-MemoryLeak-tp15891209s12049p15950613.html
>
>
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Servicemix-bean MemoryLeak

Posted by Fabrice Landrodie <fa...@alcatel-lucent.fr>.
Thank you very much Guillaume.
It works well now.

I was not aware that the behaviour and the way to code message exchange is a
bit different when unsing ServiceMixClient object or directly the
DeliveryChannel object.

Regards,
Fabrice



gnodet wrote:
> 
> I think you forgot to set and send the DONE status at the end of your
> processing,
>       MessageUtil.transferToOut(syncExchange.getMessage("out"), exchange);
>       channel.send(exchange);
>       client.done(syncExchange);
> 
> On Fri, Mar 7, 2008 at 1:29 PM, Fabrice Landrodie
> <fa...@alcatel-lucent.fr> wrote:
>>
>>  Hello,
>>
>>  I am facing some memoryleak problems when using MessageExchange and
>>  servicemix-bean.
>>
>>  My use case is as followed :
>>
>>  http client --> BC Http Su --> smx-bean Su --> smx-bean Su
>>
>>  The request send by http client is routed to the first smx-bean Su. In
>>  onMessageExchange() function, I create a new MessageExchange that I sent
>> to
>>  the second smx-bean Su using sendSync() in InOut mep. The answer is the
>>  placed into the Out of the first Exchange and send back to the BC http.
>>
>>  It works well but the problem is that if I send a lot of request, memory
>>  increases but never decrease at the end of the treatment. If I set a big
>>  size for the xml body of the request, the memory increases faster and an
>>  OutOfMemory exception is raised. So it seems the memory leak is relative
>> to
>>  the size of the message.
>>
>>  I think it could be a problem of MessageExchance that are never
>> dereferenced
>>  so that the garbage collector does not free them.
>>
>>  I use a profiler to try to analyze where the memory is leak, and it
>> seems
>>  this is in a lot of int[] and char[] objects ....
>>
>>
>>  Can someone help me on this problem ? Maybe, I do not code the good way
>> for
>>  sending message from a bean to another one.
>>
>>  Thank you for your help,
>>  Fabrice
>>
>> 
>> --------------------------------------------------------------------------------------
>>  Here is the code of the first smx-bean SU with the onMessageExchange :
>>
>>  public class MyBean implements MessageExchangeListener {
>>
>>         private static ServiceMixClient client = null;
>>
>>         @Resource
>>         private DeliveryChannel channel;
>>         @Resource
>>         private ComponentContext context;
>>
>>         public void onMessageExchange (MessageExchange exchange ) throws
>>  MessagingException {
>>
>>                 if ( client == null ) {
>>                         client = new ServiceMixClientFacade(context);
>>                 }
>>
>>                 if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
>>
>>                         if (exchange instanceof InOut == true) {
>>
>>                                 Destination destination;
>>                                 destination
>> 
>> client.createDestination("endpoint:http://myNameSpace/MyService/MyEndpoint");
>>                                 // Create New MessageExchange
>>                                 InOut syncExchange =
>> destination.createInOutExchange();
>>                                 QName qOperation = new QName("myOp");
>>                                 exchange.setOperation(qOperation);
>>
>>                                 // Get object of In Message
>>                                 NormalizedMessage request =
>> syncExchange.getInMessage();
>>                                 // Set the content of new In exchange
>> with
>>  th In coming from our caller
>>                                
>> request.setContent(exchange.getMessage("in").getContent());
>>
>>                                 // Send the new exchange and wait for the
>>  anwer
>>                                 client.sendSync(syncExchange);
>>
>>                                 // Set the out of the syncExchange into
>> the
>>  out of the current exchange and send back the current exchange
>>                                
>> MessageUtil.transferToOut(syncExchange.getMessage("out"), exchange);
>>                                 channel.send(exchange);
>>
>>                         }
>>         }
>>  }
>>  --
>>  View this message in context:
>> http://www.nabble.com/Servicemix-bean-MemoryLeak-tp15891209s12049p15891209.html
>>  Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Servicemix-bean-MemoryLeak-tp15891209s12049p15950613.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Servicemix-bean MemoryLeak

Posted by Guillaume Nodet <gn...@gmail.com>.
I think you forgot to set and send the DONE status at the end of your
processing,
      MessageUtil.transferToOut(syncExchange.getMessage("out"), exchange);
      channel.send(exchange);
      client.done(syncExchange);

On Fri, Mar 7, 2008 at 1:29 PM, Fabrice Landrodie
<fa...@alcatel-lucent.fr> wrote:
>
>  Hello,
>
>  I am facing some memoryleak problems when using MessageExchange and
>  servicemix-bean.
>
>  My use case is as followed :
>
>  http client --> BC Http Su --> smx-bean Su --> smx-bean Su
>
>  The request send by http client is routed to the first smx-bean Su. In
>  onMessageExchange() function, I create a new MessageExchange that I sent to
>  the second smx-bean Su using sendSync() in InOut mep. The answer is the
>  placed into the Out of the first Exchange and send back to the BC http.
>
>  It works well but the problem is that if I send a lot of request, memory
>  increases but never decrease at the end of the treatment. If I set a big
>  size for the xml body of the request, the memory increases faster and an
>  OutOfMemory exception is raised. So it seems the memory leak is relative to
>  the size of the message.
>
>  I think it could be a problem of MessageExchance that are never dereferenced
>  so that the garbage collector does not free them.
>
>  I use a profiler to try to analyze where the memory is leak, and it seems
>  this is in a lot of int[] and char[] objects ....
>
>
>  Can someone help me on this problem ? Maybe, I do not code the good way for
>  sending message from a bean to another one.
>
>  Thank you for your help,
>  Fabrice
>
>  --------------------------------------------------------------------------------------
>  Here is the code of the first smx-bean SU with the onMessageExchange :
>
>  public class MyBean implements MessageExchangeListener {
>
>         private static ServiceMixClient client = null;
>
>         @Resource
>         private DeliveryChannel channel;
>         @Resource
>         private ComponentContext context;
>
>         public void onMessageExchange (MessageExchange exchange ) throws
>  MessagingException {
>
>                 if ( client == null ) {
>                         client = new ServiceMixClientFacade(context);
>                 }
>
>                 if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
>
>                         if (exchange instanceof InOut == true) {
>
>                                 Destination destination;
>                                 destination
>  client.createDestination("endpoint:http://myNameSpace/MyService/MyEndpoint");
>                                 // Create New MessageExchange
>                                 InOut syncExchange = destination.createInOutExchange();
>                                 QName qOperation = new QName("myOp");
>                                 exchange.setOperation(qOperation);
>
>                                 // Get object of In Message
>                                 NormalizedMessage request = syncExchange.getInMessage();
>                                 // Set the content of new In exchange with
>  th In coming from our caller
>                                 request.setContent(exchange.getMessage("in").getContent());
>
>                                 // Send the new exchange and wait for the
>  anwer
>                                 client.sendSync(syncExchange);
>
>                                 // Set the out of the syncExchange into the
>  out of the current exchange and send back the current exchange
>                                 MessageUtil.transferToOut(syncExchange.getMessage("out"), exchange);
>                                 channel.send(exchange);
>
>                         }
>         }
>  }
>  --
>  View this message in context: http://www.nabble.com/Servicemix-bean-MemoryLeak-tp15891209s12049p15891209.html
>  Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/