curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [28/29] git commit: Nulling the watchers seems to help free more memory. I don't understand why. TODO for another day
Date Fri, 23 May 2014 15:07:29 GMT
Nulling the watchers seems to help free more memory. I don't understand why. TODO for another
day


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/9b9b9ae9
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/9b9b9ae9
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/9b9b9ae9

Branch: refs/heads/CURATOR-105
Commit: 9b9b9ae96c9c5fa423b263aba3768fc16c77a794
Parents: 0bffdb0
Author: randgalt <randgalt@apache.org>
Authored: Fri May 23 10:06:39 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Fri May 23 10:06:39 2014 -0500

----------------------------------------------------------------------
 .../recipes/cache/PathChildrenCache.java        |  9 ++-
 .../x/discovery/ServiceCacheLeakTest.java       | 61 --------------------
 .../x/discovery/ServiceCacheLeakTester.java     | 61 ++++++++++++++++++++
 3 files changed, 65 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/9b9b9ae9/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
index 04de09b..dd41b5f 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
@@ -91,7 +91,7 @@ public class PathChildrenCache implements Closeable
 
     private static final boolean USE_EXISTS = Boolean.getBoolean("curator-path-children-cache-use-exists");
 
-    private final Watcher childrenWatcher = new Watcher()
+    private volatile Watcher childrenWatcher = new Watcher()
     {
         @Override
         public void process(WatchedEvent event)
@@ -373,13 +373,12 @@ public class PathChildrenCache implements Closeable
             client.clearWatcherReferences(childrenWatcher);
             client.clearWatcherReferences(dataWatcher);
 
-/*
-            This seems to enable even more GC - I'm not sure why yet
-
+            // TODO
+            // This seems to enable even more GC - I'm not sure why yet - it
+            // has something to do with Guava's cache and circular references
             connectionStateListener = null;
             childrenWatcher = null;
             dataWatcher = null;
-*/
         }
     }
 

http://git-wip-us.apache.org/repos/asf/curator/blob/9b9b9ae9/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/ServiceCacheLeakTest.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/ServiceCacheLeakTest.java
b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/ServiceCacheLeakTest.java
deleted file mode 100644
index a8c130c..0000000
--- a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/ServiceCacheLeakTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.apache.curator.x.discovery;
-
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.retry.RetryOneTime;
-import org.apache.curator.test.TestingServer;
-import org.apache.curator.utils.CloseableUtils;
-import org.apache.curator.x.discovery.strategies.RandomStrategy;
-import org.testng.annotations.Test;
-
-public class ServiceCacheLeakTest
-{
-    @Test
-    public void serviceCacheInstancesLeaked() throws Exception
-    {
-        TestingServer testingServer = new TestingServer();
-
-        final CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(testingServer.getConnectString(),
new RetryOneTime(1));
-        try
-        {
-            curatorFramework.start();
-
-            doWork(curatorFramework);
-            System.gc();
-
-            System.out.println("Done - get dump");
-            Thread.currentThread().join();
-        }
-        finally
-        {
-            CloseableUtils.closeQuietly(curatorFramework);
-            CloseableUtils.closeQuietly(testingServer);
-        }
-    }
-
-    private void doWork(CuratorFramework curatorFramework) throws Exception
-    {
-        ServiceInstance<Void> thisInstance = ServiceInstance.<Void>builder().name("myservice").build();
-        final ServiceDiscovery<Void> serviceDiscovery = ServiceDiscoveryBuilder.builder(Void.class).client(curatorFramework.usingNamespace("dev")).basePath("/instances").thisInstance(thisInstance).build();
-        serviceDiscovery.start();
-
-        for ( int i = 0; i < 100000; i++ )
-        {
-            final ServiceProvider<Void> s = serviceProvider(serviceDiscovery, "myservice");
-            s.start();
-            try
-            {
-                s.getInstance().buildUriSpec();
-            }
-            finally
-            {
-                s.close();
-            }
-        }
-    }
-
-    private ServiceProvider<Void> serviceProvider(ServiceDiscovery<Void> serviceDiscovery,
String name) throws Exception
-    {
-        return serviceDiscovery.serviceProviderBuilder().serviceName(name).providerStrategy(new
RandomStrategy<Void>()).build();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/curator/blob/9b9b9ae9/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/ServiceCacheLeakTester.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/ServiceCacheLeakTester.java
b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/ServiceCacheLeakTester.java
new file mode 100644
index 0000000..b4e08d1
--- /dev/null
+++ b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/ServiceCacheLeakTester.java
@@ -0,0 +1,61 @@
+package org.apache.curator.x.discovery;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.TestingServer;
+import org.apache.curator.utils.CloseableUtils;
+import org.apache.curator.x.discovery.strategies.RandomStrategy;
+import org.testng.annotations.Test;
+
+public class ServiceCacheLeakTester
+{
+    @Test
+    public void serviceCacheInstancesLeaked() throws Exception
+    {
+        TestingServer testingServer = new TestingServer();
+
+        final CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(testingServer.getConnectString(),
new RetryOneTime(1));
+        try
+        {
+            curatorFramework.start();
+
+            doWork(curatorFramework);
+            System.gc();
+
+            System.out.println("Done - get dump");
+            Thread.currentThread().join();
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(curatorFramework);
+            CloseableUtils.closeQuietly(testingServer);
+        }
+    }
+
+    private void doWork(CuratorFramework curatorFramework) throws Exception
+    {
+        ServiceInstance<Void> thisInstance = ServiceInstance.<Void>builder().name("myservice").build();
+        final ServiceDiscovery<Void> serviceDiscovery = ServiceDiscoveryBuilder.builder(Void.class).client(curatorFramework.usingNamespace("dev")).basePath("/instances").thisInstance(thisInstance).build();
+        serviceDiscovery.start();
+
+        for ( int i = 0; i < 100000; i++ )
+        {
+            final ServiceProvider<Void> s = serviceProvider(serviceDiscovery, "myservice");
+            s.start();
+            try
+            {
+                s.getInstance().buildUriSpec();
+            }
+            finally
+            {
+                s.close();
+            }
+        }
+    }
+
+    private ServiceProvider<Void> serviceProvider(ServiceDiscovery<Void> serviceDiscovery,
String name) throws Exception
+    {
+        return serviceDiscovery.serviceProviderBuilder().serviceName(name).providerStrategy(new
RandomStrategy<Void>()).build();
+    }
+}
\ No newline at end of file


Mime
View raw message