Memory leak in 1.9.4.6 using multicast

112 views
Skip to first unread message

François Royer

unread,
Jan 23, 2012, 5:20:25 AM1/23/12
to Hazelcast
I 'm using hazelcast 1.9.4.6.

When I use multicast, it appear that memory is leaking until I get an
OutOfMemory Exception. It looks like an already fixed issue:

http://code.google.com/p/hazelcast/issues/detail?id=608

I see that a fix is done on trunk and an 1.9.4 branches, but 1.9.4.6
seems to still have the issue.
Can someone confirm ?

François Royer

unread,
Jan 23, 2012, 8:53:26 AM1/23/12
to Hazelcast
I'm using HazelCast version 1.9.4.6 and I have memory leak until I
got an OutOfMemoryException when I activate multicast.

It looks like an already fixed issue:

http://code.google.com/p/hazelcast/issues/detail?id=608

I see that a fix have been done on 1.9.4 and trunk branch, but I still
have leak with 1.9.4.6.

Can someone confirm that the bug is fixed or not on 1.9.4.6 version ?

Fuad Malikov

unread,
Jan 24, 2012, 7:31:23 AM1/24/12
to haze...@googlegroups.com
Hi,
That fix is already in 1.9.4.6. So may be you are observing another problem.
Can you post a code to run and see if we can replicate the issue?

-fuad


2012/1/23 François Royer <fro...@axway.com>

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To post to this group, send email to haze...@googlegroups.com.
To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.


François Royer

unread,
Jan 24, 2012, 9:20:14 AM1/24/12
to Hazelcast
Sorry for multi post, I never receive copy email of what I sent.
I will give you a short code that reproduce the leak as soon as
possible.

-François

François Royer

unread,
Jan 24, 2012, 9:58:33 AM1/24/12
to Hazelcast
here is a simple code that produce quite quickly an OutOfMemoryError
(I launch this program with -Xmx32m command line option):

import com.hazelcast.config.Config;
import com.hazelcast.config.Join;
import com.hazelcast.config.MulticastConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.core.IQueue;

public class TestMemLeak
{

/**
* @param args
*/
public static void main(String[] args)
{
Config hzConfig = new Config();
hzConfig.setProperty("hazelcast.shutdownhook.enabled",
"false");
hzConfig.getGroupConfig().setName("testmemleak");
hzConfig.getGroupConfig().setPassword("testmemleak");
hzConfig.setPort(5701);
hzConfig.setProperty("hazelcast.version.check.enabled",
"false");
Join join = hzConfig.getNetworkConfig().getJoin();

// set Multicast support enable
MulticastConfig multicastConfig = join.getMulticastConfig();
multicastConfig.setEnabled(true);

HazelcastInstance hzInstance =
Hazelcast.newHazelcastInstance(hzConfig);
IMap<String, String> tmap = hzInstance.getMap("testmemleak-
map");
tmap.put("key", "value");
IQueue<String> tqueue = hzInstance.getQueue("testmemleak-
queue");
try
{
tqueue.put("message");
}
catch (InterruptedException e)
{
e.printStackTrace();
}

hzConfig.setPort(5702);
while (true) {
HazelcastInstance hzInstance2 =
Hazelcast.newHazelcastInstance(hzConfig);
System.out.println(hzInstance2.getQueue("testmemleak-
queue").peek());
hzInstance2.getLifecycleService().shutdown();
hzInstance2 = null;
System.gc();
}
}
}

Fuad Malikov

unread,
Jan 26, 2012, 1:23:29 PM1/26/12
to haze...@googlegroups.com
We just committed to the trunk a code that should improve the situation. Can you please try and see if it solves it. I run your code and everything seems to be fine. You should compile and run the trunk by yourself!

-fuad


2012/1/24 François Royer <fro...@axway.com>
       }
   }
}

Royer François (Ag 422)

unread,
Jan 30, 2012, 3:29:58 AM1/30/12
to haze...@googlegroups.com

Hello Fuad,

 

So I try with trunk and the above program still have leak. It seems that calling hazelcast shutdown() and removing reference to it do not free associated memory. If there is something more to do to get memory back, please tell me.

 

In fact, this program leak memory with ou without using multicast, so it’s not the use case we have in our software.

I’m going to investigate more on our software to find out what cause our memory leak. I will give you update on this as soon as possible.

 

François

 

 

 

De : haze...@googlegroups.com [mailto:haze...@googlegroups.com] De la part de Fuad Malikov
Envoyé : jeudi 26 janvier 2012 19:23
À : haze...@googlegroups.com
Objet : Re: Memory leak in 1.9.4.6 using multicast

Royer François (Ag 422)

unread,
Feb 3, 2012, 4:58:49 AM2/3/12
to haze...@googlegroups.com

Hello Fuad,

 

I’m back after some day spent to produce the same leak as we have in your software. Here is the new version of the program.

The thing is that the leak seems very small and slow, and I didn’t find a way to maximize or speed up it. The new version is starting a new process inside a loop and wait for it to stop. So it has only one HazelCast instance / process.  The new process do some job with a HazelCast  map and queue and exit.  The size of the queue and the map remain constant during the test.

When I launch this program with a small heap size (10MB), the program can do a litle more than  40 iterations before I get the java.lang.OutOfMemoryError: Java heap space. If I turn multicast off, it can  run more than 1000 iterations…

I try this program with Hazelcast beta 2 after changing the itemlistener, but it failed randomly with OutOfMemory or joining fails…

 

Hope it will help.

 

 

import java.io.File;

import java.net.InetSocketAddress;

import java.util.Collections;

import java.util.Map;

 

import com.hazelcast.config.Config;

import com.hazelcast.config.Join;

import com.hazelcast.config.MulticastConfig;

import com.hazelcast.core.Hazelcast;

import com.hazelcast.core.HazelcastInstance;

import com.hazelcast.core.IMap;

import com.hazelcast.core.IQueue;

import com.hazelcast.core.ItemListener;

import com.hazelcast.core.MembershipEvent;

import com.hazelcast.core.MembershipListener;

 

public class TestMemLeak implements MembershipListener, ItemListener<String>

{

    static IQueue<String> tqueue = null;

 

    public TestMemLeak()

    {

        // TODO Auto-generated constructor stub

    }

 

    public void memberAdded(MembershipEvent evt)

    {

        System.out.println(">" + evt.getMember());

    }

 

    public void memberRemoved(MembershipEvent evt)

    {

        System.out.println("<" + evt.getMember());

    }

 

    @Override

    public void itemAdded(String arg0)

    {

        tqueue.poll();

    }

 

    @Override

    public void itemRemoved(String arg0)

    {

        // TODO Auto-generated method stub

       

    }

    public static void main(String[] args)

    {

        System.setProperty("hazelcast.logging.type", "none");

 

        boolean multicast = true;

        boolean client = false;

        String member = null;

 

        for (String s : args)

        {

            if (s.equals("-nomulticast"))

                multicast = false;

            else if (s.equals("-client"))

                client = true;

            else

                member = s;

        }

 

        Config hzConfig = new Config();

        hzConfig.setProperty("hazelcast.shutdownhook.enabled", "false");

        hzConfig.getGroupConfig().setName("testmemleak");

        hzConfig.getGroupConfig().setPassword("testmemleak");

        hzConfig.setProperty("hazelcast.version.check.enabled", "false");

        Join join = hzConfig.getNetworkConfig().getJoin();

 

        // set Multicast support

        MulticastConfig multicastConfig = join.getMulticastConfig();

        multicastConfig.setEnabled(multicast);

        join.getTcpIpConfig().setEnabled(true);

 

        if (client && !multicast && member != null)

            join.getTcpIpConfig().addMember(member);

 

        TestMemLeak testMemLeak = new TestMemLeak();

        HazelcastInstance hzInstance = Hazelcast.newHazelcastInstance(hzConfig);

        InetSocketAddress isa = hzInstance.getCluster().getLocalMember().getInetSocketAddress();

 

        String lmember = isa.getAddress().getHostAddress() + ":" + isa.getPort();

 

        tqueue = hzInstance.getQueue("testmemleak-queue");

       

        tqueue.addItemListener(testMemLeak, true);

       

        if (client)

            doSomeWorkAndExit(hzInstance, testMemLeak);

 

        hzInstance.getCluster().addMembershipListener(testMemLeak);

        IMap<String, String> tmap = hzInstance.getMap("testmemleak-map");

       

        tmap.put("key", "value");

        for (int i=0 ;i<500; i++)

            tmap.put("key"+i, "value"+i);

 

        StringBuilder sb = new StringBuilder();

        sb.append(System.getProperty("java.home")).append(File.separatorChar).append("bin").append(File.separatorChar).append("java ").append("-cp ")

            .append(System.getProperty("java.class.path")).append(" TestMemLeak -client");

        if (!multicast)

            sb.append(" -nomulticast ").append(lmember);

 

        Map<String, String> c;

        int icount=0;

        while (true)

        {

            try

            {

                try

                {

                    System.out.println("iteration N°" + icount++ +", tqueue.size()=" + tqueue.size() + ", tmap.size()=" + tmap.size());

                    c = Collections.unmodifiableMap(tmap);

                    tqueue.put("parent message");

                    tmap.put("key", "parent value");

                }

                catch(Exception e)

                {

                    e.printStackTrace();

                }

                Process p = Runtime.getRuntime().exec(sb.toString());

                p.waitFor();

            }

            catch (Exception e)

            {

                e.printStackTrace();

                break;

            }

        }

    }

 

    private static void doSomeWorkAndExit(HazelcastInstance hzInstance, TestMemLeak tml)

    {

        try

        {

            tqueue.put("client message");

            IMap<String, String> tmap = hzInstance.getMap("testmemleak-map");

            tmap.put("key", "client value");

        }

        catch (Exception e)

        {

            //

        }

        hzInstance.getCluster().removeMembershipListener(tml);

        tqueue.removeItemListener(tml);

        hzInstance.getLifecycleService().shutdown();

        System.exit(0);

    }

}

 

De : haze...@googlegroups.com [mailto:haze...@googlegroups.com] De la part de Fuad Malikov
Envoyé : jeudi 26 janvier 2012 19:23
À : haze...@googlegroups.com
Objet : Re: Memory leak in 1.9.4.6 using multicast

 

We just committed to the trunk a code that should improve the situation. Can you please try and see if it solves it. I run your code and everything seems to be fine. You should compile and run the trunk by yourself!

-fuad

François Royer

unread,
Feb 13, 2012, 9:52:41 AM2/13/12
to haze...@googlegroups.com
I test again with release 1.9.4.8 and I still have out of memory error when using multicast...

Is there any things I can do to help ?



Fuad Malikov

unread,
Feb 22, 2012, 9:14:01 AM2/22/12
to haze...@googlegroups.com
Hi François,

Can you try 2.0 RC2. I run with the latest in trunk(didn't change much after RC2) with 8M Xmx and it iterated over 700, until I killed the process. 



2012/2/13 François Royer <fro...@axway.com>
I test again with release 1.9.4.8 and I still have out of memory error when using multicast...

Is there any things I can do to help ?

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hazelcast/-/opDy4HMVBxIJ.
Reply all
Reply to author
Forward
0 new messages