brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [5/6] brooklyn-server git commit: switch to computing based on max memory not total, and other minor fixes from code review
Date Mon, 26 Sep 2016 10:37:59 GMT
switch to computing based on max memory not total, and other minor fixes from code review


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/61073c64
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/61073c64
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/61073c64

Branch: refs/heads/master
Commit: 61073c644b26231e4d7b8d7378acca82b4909c15
Parents: 457c8d4
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Sep 26 10:42:31 2016 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Sep 26 10:42:31 2016 +0100

----------------------------------------------------------------------
 .../camp/spi/collection/BasicResourceLookup.java   | 17 ++++++++---------
 .../camp/spi/pdp/AssemblyTemplateConstructor.java  |  2 +-
 .../brooklyn/camp/brooklyn/EntitiesYamlTest.java   |  2 +-
 .../mgmt/internal/BrooklynGarbageCollector.java    | 11 ++++++++---
 .../brooklyn/util/javalang/MemoryUsageTracker.java |  6 +++---
 5 files changed, 21 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/61073c64/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/collection/BasicResourceLookup.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/collection/BasicResourceLookup.java
b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/collection/BasicResourceLookup.java
index 52850a6..1941aa3 100644
--- a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/collection/BasicResourceLookup.java
+++ b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/collection/BasicResourceLookup.java
@@ -43,16 +43,15 @@ public class BasicResourceLookup<T extends AbstractResource> extends
AbstractRes
     }
 
     public synchronized void add(T item) {
-        T old = items.put(item.getId(), item);
-        if (old!=null) {
-            items.put(old.getId(), old);
-            throw new IllegalStateException("Already contains item for "+item.getId()+":
"+old+" (adding "+item+")");
-        } else {
-            if (!items.isEmpty() && items.size()%100==0) {
-                // useful for monitoring any leaks here
-                log.debug("Creating new CAMP item in "+this+" (had "+(items.size())+"): "+item);
-            }
+        if (items.containsKey(item.getId())) {
+            throw new IllegalStateException("Already contains item for "+item.getId()+" (adding
"+item+")");
+        }
+        
+        if (!items.isEmpty() && items.size()%100==0) {
+            // useful for monitoring any leaks here
+            log.debug("Creating new CAMP item in "+this+" (had "+(items.size())+"): "+item);
         }
+        items.put(item.getId(), item);
         links.put(item.getId(), newLink(item.getId(), item.getName()));
     }
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/61073c64/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
index a236148..81a86fa 100644
--- a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
+++ b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
@@ -43,7 +43,7 @@ public class AssemblyTemplateConstructor {
     /** records all the templates to the underlying platform 
      * @deprecated since 0.10.0 use {@link #construct(boolean)} */
     public AssemblyTemplate commit() {
-        return construct(false);
+        return construct(true);
     }
     
     /** builds the template, optionally recording everything to the underlying platform */

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/61073c64/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
index 92d9adc..f7b13b3 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
@@ -1081,7 +1081,7 @@ public class EntitiesYamlTest extends AbstractYamlTest {
     }
 
     @Test
-    public void testLeakWithPct() throws Exception {
+    public void testLeakyPlatformComponentTemplate() throws Exception {
         String yaml = loadYaml("same-server-entity-test.yaml");
         doTestLeak(yaml);
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/61073c64/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java
index a66821f..60dae0e 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/BrooklynGarbageCollector.java
@@ -210,7 +210,7 @@ public class BrooklynGarbageCollector {
             gcTasks();
             logUsage("brooklyn gc (after)");
             
-            double memUsage = 1.0 - 1.0*Runtime.getRuntime().freeMemory() / Runtime.getRuntime().totalMemory();
+            double memUsage = 1.0 - 1.0*Runtime.getRuntime().freeMemory() / Runtime.getRuntime().maxMemory();
             if (memUsage > brooklynProperties.getConfig(FORCE_CLEAR_SOFT_REFERENCES_ON_MEMORY_USAGE_LEVEL))
{
                 LOG.info("Forcing brooklyn gc including soft-reference cleansing due to memory
usage: "+getUsageString());
                 MemoryUsageTracker.forceClearSoftReferences();
@@ -237,8 +237,13 @@ public class BrooklynGarbageCollector {
 
     public static String makeBasicUsageString() {
         int present = (int)Math.round(100.0*SoftlyPresent.getUsageTracker().getPercentagePresent());
-        return Strings.makeSizeString(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())+"
/ "+
-            Strings.makeSizeString(Runtime.getRuntime().totalMemory()) + " memory; " +
+        return Strings.makeSizeString(Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory())+"
/ "+
+            Strings.makeSizeString(Runtime.getRuntime().maxMemory()) 
+            + (Runtime.getRuntime().maxMemory() > Runtime.getRuntime().totalMemory() ?

+                " ("+ Strings.makeSizeString(Runtime.getRuntime().totalMemory()) +" real)"
+                : "")
+            + " memory"
+            + "; " +
             (present>=0 ? present+"% soft-reference maybe retention (of "+SoftlyPresent.getUsageTracker().getTotalEntries()+");
" : "") +
             Thread.activeCount()+" threads";
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/61073c64/utils/common/src/main/java/org/apache/brooklyn/util/javalang/MemoryUsageTracker.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/javalang/MemoryUsageTracker.java
b/utils/common/src/main/java/org/apache/brooklyn/util/javalang/MemoryUsageTracker.java
index acfdfaa..57a645e 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/javalang/MemoryUsageTracker.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/javalang/MemoryUsageTracker.java
@@ -90,7 +90,7 @@ public class MemoryUsageTracker {
 
     /** forces all soft references to be cleared by trying to allocate an enormous chunk
of memory,
      * returns a description of what was done 
-     * (tune with with {@link #forceClearSoftReferences(long, int)} 
+     * (tune with {@link #forceClearSoftReferences(long, int)} 
      * for greater than 200M precision in the output message, if you really care about that)
*/
     public static String forceClearSoftReferences() {
         return forceClearSoftReferences(1000*1000, Integer.MAX_VALUE);
@@ -138,8 +138,8 @@ public class MemoryUsageTracker {
         public synchronized void disable() {
             cache = null;
         }
-        public long getTotalEntries() {
-            return cache.size();
+        public synchronized long getTotalEntries() {
+            return cache==null ? -1 : cache.size();
         }
         public synchronized double getPercentagePresent() {
             if (cache==null) return -1;


Mime
View raw message