curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pavan Kumar M S (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CURATOR-312) Memory leak of NamespaceWatcher when register TreeCacheListener to non-existing path
Date Fri, 25 Mar 2016 07:08:25 GMT

     [ https://issues.apache.org/jira/browse/CURATOR-312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Pavan Kumar M S updated CURATOR-312:
------------------------------------
    Description: 
Hi, 
    
     As per the Curator API document its allowed to register the TreeCacheListener to the
path which is not present in the broker, but when we try to register its found that object
'NamespaceWatcher' keep on increasing and leading to out of memory in very short time. 

   Following is the sample code which can be used to reproduce the issue. 

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.CuratorFrameworkFactory.Builder;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.retry.RetryNTimes;

public class TreeCacheProblem
{
    private static final int RETRYTIMES = 3;

    private static final int RETRYINTERVAL = 1000;

    private static final int CONNECTION_TIME_OUT = 3000;

    private static final int SESSION_TIME_OUT = 5000;

    public static void main ( String [] args ) throws Exception
    {
        TreeCacheProblem treeCache = new TreeCacheProblem();
        treeCache.init ( "10.18.104.149:2189" );
        String zkPath = "/home/sample";
        treeCache.addTreeCacheListener ( zkPath, new TreeCacheListener(){

            public void childEvent ( CuratorFramework client, TreeCacheEvent event )
                throws Exception
            {
                 System.out.println (event);
            }

        });


        System.in.read();
    }

    private CuratorFramework client;

    private void init ( String zkURL )
    {
        Builder connect = CuratorFrameworkFactory.builder ().connectString ( zkURL );

        this.client = connect.retryPolicy ( new RetryNTimes ( RETRYTIMES, RETRYINTERVAL )
)
            .connectionTimeoutMs ( CONNECTION_TIME_OUT ).sessionTimeoutMs ( SESSION_TIME_OUT
)
            .build ();
        this.client.start ();
    }

    public void addTreeCacheListener ( String zkPath, TreeCacheListener treeCacheListener
) throws Exception
    {

        org.apache.curator.framework.recipes.cache.TreeCache.Builder builder = TreeCache
            .newBuilder ( client, zkPath );
        builder.setCacheData ( true );
        TreeCache treeCache = builder.build ();
        treeCache.getListenable ().addListener ( treeCacheListener );
        treeCache.start ();

    }
}


Curator API Doc for reference 

https://curator.apache.org/apidocs/org/apache/curator/framework/recipes/cache/TreeCache.html

public TreeCache(CuratorFramework client,
                 String path)
Create a TreeCache for the given client and path with default options.
If the client is namespaced, all operations on the resulting TreeCache will be in terms of
the namespace, including all published events. The given path is the root at which the TreeCache
will watch and explore. If no node exists at the given path, the TreeCache will be initially
empty.

Parameters:
client - the client to use; may be namespaced
path - the path to the root node to watch/explore; this path need not actually exist on the
server
See Also:
newBuilder(CuratorFramework, String)





With Regards,
Pavan

  was:
Hi, 
    
     As per the Curator API document its allowed to register the TreeCacheListener to the
path which is not present in the broker, but when we try to register its found that object
'NamespaceWatcher' keep on increasing and leading to out of memory in very short time. 

   Following is the sample code which can be used to reproduce the issue. 

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.CuratorFrameworkFactory.Builder;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.retry.RetryNTimes;

public class TreeCacheProblem
{
    private static final int RETRYTIMES = 3;

    private static final int RETRYINTERVAL = 1000;

    private static final int CONNECTION_TIME_OUT = 3000;

    private static final int SESSION_TIME_OUT = 5000;

    public static void main ( String [] args ) throws Exception
    {
        TreeCacheProblem treeCache = new TreeCacheProblem();
        treeCache.init ( "10.18.104.149:2189" );
        String zkPath = "/home/sample";
        treeCache.addTreeCacheListener ( zkPath, new TreeCacheListener(){

            public void childEvent ( CuratorFramework client, TreeCacheEvent event )
                throws Exception
            {
                 System.out.println (event);
            }

        });


        System.in.read();
    }

    private CuratorFramework client;

    private void init ( String zkURL )
    {
        Builder connect = CuratorFrameworkFactory.builder ().connectString ( zkURL );

        this.client = connect.retryPolicy ( new RetryNTimes ( RETRYTIMES, RETRYINTERVAL )
)
            .connectionTimeoutMs ( CONNECTION_TIME_OUT ).sessionTimeoutMs ( SESSION_TIME_OUT
)
            .build ();
        this.client.start ();
    }

    public void addTreeCacheListener ( String zkPath, TreeCacheListener treeCacheListener
) throws Exception
    {

        org.apache.curator.framework.recipes.cache.TreeCache.Builder builder = TreeCache
            .newBuilder ( client, zkPath );
        builder.setCacheData ( true );
        TreeCache treeCache = builder.build ();
        treeCache.getListenable ().addListener ( treeCacheListener );
        treeCache.start ();

    }
}






With Regards,
Pavan


> Memory leak of NamespaceWatcher when register TreeCacheListener to non-existing path
> ------------------------------------------------------------------------------------
>
>                 Key: CURATOR-312
>                 URL: https://issues.apache.org/jira/browse/CURATOR-312
>             Project: Apache Curator
>          Issue Type: Bug
>          Components: Recipes
>    Affects Versions: 2.8.0
>         Environment: Suse Linux + JDK 1.8 
> Windows 7 + JDK 1.7
>            Reporter: Pavan Kumar M S
>             Fix For: awaiting-response
>
>
> Hi, 
>     
>      As per the Curator API document its allowed to register the TreeCacheListener to
the path which is not present in the broker, but when we try to register its found that object
'NamespaceWatcher' keep on increasing and leading to out of memory in very short time. 
>    Following is the sample code which can be used to reproduce the issue. 
> import org.apache.curator.framework.CuratorFramework;
> import org.apache.curator.framework.CuratorFrameworkFactory;
> import org.apache.curator.framework.CuratorFrameworkFactory.Builder;
> import org.apache.curator.framework.recipes.cache.TreeCache;
> import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
> import org.apache.curator.framework.recipes.cache.TreeCacheListener;
> import org.apache.curator.retry.RetryNTimes;
> public class TreeCacheProblem
> {
>     private static final int RETRYTIMES = 3;
>     private static final int RETRYINTERVAL = 1000;
>     private static final int CONNECTION_TIME_OUT = 3000;
>     private static final int SESSION_TIME_OUT = 5000;
>     public static void main ( String [] args ) throws Exception
>     {
>         TreeCacheProblem treeCache = new TreeCacheProblem();
>         treeCache.init ( "10.18.104.149:2189" );
>         String zkPath = "/home/sample";
>         treeCache.addTreeCacheListener ( zkPath, new TreeCacheListener(){
>             public void childEvent ( CuratorFramework client, TreeCacheEvent event )
>                 throws Exception
>             {
>                  System.out.println (event);
>             }
>         });
>         System.in.read();
>     }
>     private CuratorFramework client;
>     private void init ( String zkURL )
>     {
>         Builder connect = CuratorFrameworkFactory.builder ().connectString ( zkURL );
>         this.client = connect.retryPolicy ( new RetryNTimes ( RETRYTIMES, RETRYINTERVAL
) )
>             .connectionTimeoutMs ( CONNECTION_TIME_OUT ).sessionTimeoutMs ( SESSION_TIME_OUT
)
>             .build ();
>         this.client.start ();
>     }
>     public void addTreeCacheListener ( String zkPath, TreeCacheListener treeCacheListener
) throws Exception
>     {
>         org.apache.curator.framework.recipes.cache.TreeCache.Builder builder = TreeCache
>             .newBuilder ( client, zkPath );
>         builder.setCacheData ( true );
>         TreeCache treeCache = builder.build ();
>         treeCache.getListenable ().addListener ( treeCacheListener );
>         treeCache.start ();
>     }
> }
> Curator API Doc for reference 
> https://curator.apache.org/apidocs/org/apache/curator/framework/recipes/cache/TreeCache.html
> public TreeCache(CuratorFramework client,
>                  String path)
> Create a TreeCache for the given client and path with default options.
> If the client is namespaced, all operations on the resulting TreeCache will be in terms
of the namespace, including all published events. The given path is the root at which the
TreeCache will watch and explore. If no node exists at the given path, the TreeCache will
be initially empty.
> Parameters:
> client - the client to use; may be namespaced
> path - the path to the root node to watch/explore; this path need not actually exist
on the server
> See Also:
> newBuilder(CuratorFramework, String)
> With Regards,
> Pavan



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message