You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by sandeep reddy <sa...@in2m.com> on 2008/08/21 17:25:59 UTC

Memory leak problem with servicemix-bean

Hi Servicemix-guys,

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

Use case is as followed :

Client --> Http Consumer SU --> Bean SU --> Camel SU --> Http Provider Su
--> External Service

onMessageExchange() function code:

    public void onMessageExchange(MessageExchange exchange) throws
MessagingException {
        try {
        if (exchange.getStatus() != ExchangeStatus.ACTIVE){
            return;
        }
       
        NormalizedMessage message = exchange.getMessage("in");
       
        Set<Principal> principals =
message.getSecuritySubject().getPrincipals();
        String roleString = "";
        Iterator<Principal> principalIterator = principals.iterator();
        while (principalIterator.hasNext()) {
            Principal element = (Principal) principalIterator.next();
            roleString += element.getName();
            if(principalIterator.hasNext()) {
                roleString += ",";
            }
        }
               
        ClientFactory factory = (ClientFactory) new
InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
        ServiceMixClient client = factory.createClient();       
        Destination destination =
client.createDestination(getValidateService());
        InOut inOutExchange = destination.createInOutExchange();
        inOutExchange.setProperty("org.apache.servicemix.correlationId",
exchange.getProperty("org.apache.servicemix.correlationId"));
        NormalizedMessage inMessage = inOutExchange.getInMessage();
        inMessage.setProperty("userPrincipals",roleString);
        inMessage.setContent(message.getContent());
        client.sendSync(inOutExchange);
       
        NormalizedMessage outMessage = inOutExchange.getOutMessage();
        inOutExchange.setStatus(ExchangeStatus.DONE);
        exchange.setMessage(outMessage,"out");
        channel.send(exchange);
       
        } catch (Exception e) {
            logger.error("Error in processing message ",e);
        }       
  }

It works fine but the problem is that if I send a lot of parallel requests
at a time then it create number of threads and also increases memory
dramatically but never decrease even at the end of the request (observed
using jconsole).

So, that it seams to be some thing is missing in my above code.Can some body
help me on this.
Please ......

Sandeep.

-- 
View this message in context: http://www.nabble.com/Memory-leak-problem-with-servicemix-bean-tp19091115p19091115.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Memory leak problem with servicemix-bean

Posted by Gert Vanthienen <ge...@skynet.be>.
Sandeep,

The problem is probably with the InOut exchange you are sending.  If you
look at the Invocation example diagram on
http://servicemix.apache.org/5-jbi.html, you'll notice that the
MessageExchange ends by sending a DONE MessageExchange.  The easiest way to
do this is by calling client.done(inOutExchange).

In your code, you do set the DONE status but you never send the
MessageExchange with this status.  Without sending the exchange, other
components in the ESB are unable to determine that the MessageExchange has
ended. 

Secondly, I would recommend you to avoid creating the JNDI context and
looking up the ServiceMixClient over and over again.  These two lines are
probably the most expensive in terms of workload/performance, so if you can
create it and cache it somewhere, that would be a big step ahead.

Regards,

Gert


sandeep reddy wrote:
> 
> Hi Servicemix-guys,
> 
> I am facing some memoryleak problems when using servicemix-bean.
> 
> Use case is as followed :
> 
> Client --> Http Consumer SU --> Bean SU --> Camel SU --> Http Provider Su
> --> External Service
> 
> onMessageExchange() function code:
> 
>     public void onMessageExchange(MessageExchange exchange) throws
> MessagingException {
>         try {
>         if (exchange.getStatus() != ExchangeStatus.ACTIVE){
>             return;
>         }
>        
>         NormalizedMessage message = exchange.getMessage("in");
>        
>         Set<Principal> principals =
> message.getSecuritySubject().getPrincipals();
>         String roleString = "";
>         Iterator<Principal> principalIterator = principals.iterator();
>         while (principalIterator.hasNext()) {
>             Principal element = (Principal) principalIterator.next();
>             roleString += element.getName();
>             if(principalIterator.hasNext()) {
>                 roleString += ",";
>             }
>         }
>                
>         ClientFactory factory = (ClientFactory) new
> InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
>         ServiceMixClient client = factory.createClient();       
>         Destination destination =
> client.createDestination(getValidateService());
>         InOut inOutExchange = destination.createInOutExchange();
>         inOutExchange.setProperty("org.apache.servicemix.correlationId",
> exchange.getProperty("org.apache.servicemix.correlationId"));
>         NormalizedMessage inMessage = inOutExchange.getInMessage();
>         inMessage.setProperty("userPrincipals",roleString);
>         inMessage.setContent(message.getContent());
>         client.sendSync(inOutExchange);
>        
>         NormalizedMessage outMessage = inOutExchange.getOutMessage();
>         inOutExchange.setStatus(ExchangeStatus.DONE);
>         exchange.setMessage(outMessage,"out");
>         channel.send(exchange);
>        
>         } catch (Exception e) {
>             logger.error("Error in processing message ",e);
>         }       
>   }
> 
> It works fine but the problem is that if I send a lot of parallel requests
> at a time then it create number of threads and also increases memory
> dramatically but never decrease even at the end of the request (observed
> using jconsole).
> 
> So, that it seams to be some thing is missing in my above code.Can some
> body help me on this.
> Please ......
> 
> Sandeep.
> 
> 


-----
---
Gert Vanthienen
http://www.anova.be
-- 
View this message in context: http://www.nabble.com/Memory-leak-problem-with-servicemix-bean-tp19091115p19096252.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Memory leak problem with servicemix-bean

Posted by jawed <ja...@sabre-holdings.com>.


sandeep reddy wrote:
> 
> Hi Servicemix-guys,
> 
> I am facing some memoryleak problems when using servicemix-bean.
> 
> Use case is as followed :
> 
> Client --> Http Consumer SU --> Bean SU --> Camel SU --> Http Provider Su
> --> External Service
> 
> onMessageExchange() function code:
> 
>     public void onMessageExchange(MessageExchange exchange) throws
> MessagingException {
>         try {
>         if (exchange.getStatus() != ExchangeStatus.ACTIVE){
>             return;
>         }
>        
>         NormalizedMessage message = exchange.getMessage("in");
>        
>         Set<Principal> principals =
> message.getSecuritySubject().getPrincipals();
>         String roleString = "";
>         Iterator<Principal> principalIterator = principals.iterator();
>         while (principalIterator.hasNext()) {
>             Principal element = (Principal) principalIterator.next();
>             roleString += element.getName();
>             if(principalIterator.hasNext()) {
>                 roleString += ",";
>             }
>         }
>                
>         ClientFactory factory = (ClientFactory) new
> InitialContext().lookup(ClientFactory.DEFAULT_JNDI_NAME);
>         ServiceMixClient client = factory.createClient();       
>         Destination destination =
> client.createDestination(getValidateService());
>         InOut inOutExchange = destination.createInOutExchange();
>         inOutExchange.setProperty("org.apache.servicemix.correlationId",
> exchange.getProperty("org.apache.servicemix.correlationId"));
>         NormalizedMessage inMessage = inOutExchange.getInMessage();
>         inMessage.setProperty("userPrincipals",roleString);
>         inMessage.setContent(message.getContent());
>         client.sendSync(inOutExchange);
>        
>         NormalizedMessage outMessage = inOutExchange.getOutMessage();
>         inOutExchange.setStatus(ExchangeStatus.DONE);
>         exchange.setMessage(outMessage,"out");
>         channel.send(exchange);
>        
>         } catch (Exception e) {
>             logger.error("Error in processing message ",e);
>         }       
>   }
> 
> It works fine but the problem is that if I send a lot of parallel requests
> at a time then it create number of threads and also increases memory
> dramatically but never decrease even at the end of the request (observed
> using jconsole).
> 
> So, that it seams to be some thing is missing in my above code.Can some
> body help me on this.
> Please ......
> 
> Sandeep.
> 
> 


The Http consumer endpoint (https) had memory leak too which was most
recent. 
Jawed

-- 
View this message in context: http://www.nabble.com/Memory-leak-problem-with-servicemix-bean-tp19091115p19107179.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.