1 2 3 Previous Next 39 Replies Latest reply on Jun 22, 2006 4:37 AM by mwelss Go to original post
      • 30. Re: Security Exception
        timfox

         

        "mwelss" wrote:
        Tim,

        the memory leak becomes visible very quickly with my testcase, it will eat 1-2 MB every minute.
        BUT: I didn't try your configuration yet, I can reproduce this reliably on jboss 4.0.4.GA-patch1 with ejb3 config and jboss-messaging 1.0.1CR2. I will try with EJB3-RC8 this afternoon and keep you informed :-)

        Best regards,

        Martin


        Martin - which version of EJB3 are you running?

        • 31. Re: Security Exception
          timfox

          Ok, a few things to report.

          The call to rt.gc() in ClientServlet really slowed things down, so I removed it.

          I then noticed that memory became exhausted (500MB) in a few minutes.

          I also managed to replicate this using a simple self contained jms program (using no EJBs) which simply sends messages to a queue, which are then picked up by a message listener and sent on to a topic where they are consumed by two subscribers with selectors, exactly the same as your example but using straightforward jms - no ejbs.

          Looking more closely at your code and noticed the cause of the leak:

          in PlexMDB, when the message is received it sends 4 more messages to the topic:

          ObjectMessage reply = session.createObjectMessage();
           reply.setStringProperty("target", "10");
           reply.setIntProperty("cnt", cnt);
           reply.setObject(payload);
           producer.send(reply);
           reply = session.createObjectMessage();
           reply.setStringProperty("target", "20");
           reply.setIntProperty("cnt", cnt);
           reply.setObject(payload);
           producer.send(reply);
           reply = session.createObjectMessage();
           reply.setStringProperty("target", "30");
           reply.setIntProperty("cnt", cnt);
           reply.setObject(payload);
           producer.send(reply);
           reply = session.createObjectMessage();
           reply.setStringProperty("target", "40");
           reply.setIntProperty("cnt", cnt);
           reply.setObject(payload);
          


          In ClientServlet after sending a message the thread synchronously waits to receive two messages - one from each consumer, before continuing and sending the next message.

          However, the consumers should receive 2 messages *each* since the selector matches target = 10 OR target = 20.

          Therefore the code should be changed to receive four message not two:

          log.info("Message "+i+"/"+count+" was successfully sent to the " + queue.getQueueName() + " queue");
          
           message = (ObjectMessage) consumer1.receive();
           ArrayList v1 = (ArrayList) message.getObject();
          
           message = (ObjectMessage) consumer2.receive();
           ArrayList v2 = (ArrayList) message.getObject();
          
           message = (ObjectMessage) consumer1.receive();
           v1 = (ArrayList) message.getObject();
          
           message = (ObjectMessage) consumer2.receive();
           v2 = (ArrayList) message.getObject();
          
           log.info("Received messages, size: " + (v1.size() + v2.size()));
          


          Before contining to send the next message.

          Because the original code was only waiting to receive two messages, then the sends were executing faster than messages were being consumed and eventually memory would get exhausted since messages were building up on the subscriptions.

          When I change the code to wait for four messages, I can run my test program for extended periods without exhausting memory.

          I shall now try running it on my test box for several hours to make sure, but I think this is the problem.

          • 32. Re: Security Exception
            timfox

            So, with the rt.gc, the system would also have run out of memory eventually, but I guess it was slowing things down so much on my system that I didn't run it long enough to notice

            • 33. Re: Security Exception
              mwelss


              Martin - which version of EJB3 are you running?


              the one that comes with jboss 4.0.4.GA-patch1. Rumors say it could be RC6...

              • 34. Re: Security Exception
                mwelss

                 

                in PlexMDB, when the message is received it sends 4 more messages to the topic:


                Yes, that is all on purpose: this is where the selectors enter the game!
                If you look at the client, it creates consumers (using the selctor) for targets 10 or 20

                But the MDB sends one message each to the targets 10, 20, 30, and 40.
                So, only the first two should be delivered to the client and the last two should be discarded by jms because there is no subscriber!

                • 35. Re: Security Exception
                  timfox

                  No, that's not quite correct.

                  You are creating *two* consumers, each with the same selector expression ""target='10' OR target='20'"

                  For each message sent to the queue you are posting 4 messages, with target =10, 20, 30, 40

                  Therefore *both* of the two consumers will *each* receive the first two messages.

                  But in your code you are only waiting to receive *two* messages in total.

                  Think about it....

                  Remember, this is a topic so each subscription will get all messages that match the selector, in this case each suibscription will receive 2 messages.

                  • 36. Re: Security Exception
                    mwelss

                    Yes, you are absolutely right! Shame on me.

                    The bad news is, that it seems like I did not 'extract' the testcase sucessfully or it takes longer for the leak to appear...

                    • 37. Re: Security Exception
                      timfox

                      Martin - I have tried out your latest test case, and I confirm that I observe a memory leak.

                      After a lot of grief I have tracked it down to a race condition in message acknowledgement that only occurs when used with EJB3.

                      I won't bore you with the details, but I am running your test case again now and not observing any more leaks - I shall put a million 100K messages through it over night to make sure.

                      • 38. Re: Security Exception
                        timfox

                        Martin-I ran your test program with 500000 messages - it took a few hours and after my fix I didn't notice any memory leak.

                        This fix will be in the 1.0.1GA release which should be out fairly soon once we've cleared up this latest few issues we are having.

                        • 39. Re: Security Exception
                          mwelss

                          Sounds great. Thanks!

                          1 2 3 Previous Next