jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1526206 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: cache/EmpiricalWeigher.java plugins/mongomk/NodeDocument.java plugins/mongomk/Revision.java plugins/mongomk/util/Utils.java
Date Wed, 25 Sep 2013 15:29:57 GMT
Author: mreutegg
Date: Wed Sep 25 15:29:57 2013
New Revision: 1526206

URL: http://svn.apache.org/r1526206
Log:
OAK-1041: Inaccurate size estimate in EmpiricalWeigher
- adjust memory estimates
- do not cache string representation of Revision anymore

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/EmpiricalWeigher.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Revision.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/Utils.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/EmpiricalWeigher.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/EmpiricalWeigher.java?rev=1526206&r1=1526205&r2=1526206&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/EmpiricalWeigher.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/cache/EmpiricalWeigher.java
Wed Sep 25 15:29:57 2013
@@ -30,7 +30,7 @@ public class EmpiricalWeigher implements
 
     @Override
     public int weigh(String key, CacheValue value) {
-        return key.length() * 2 + value.getMemory();
+        return 48 + key.length() * 2 + value.getMemory();
     }
     
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java?rev=1526206&r1=1526205&r2=1526206&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/NodeDocument.java
Wed Sep 25 15:29:57 2013
@@ -978,9 +978,9 @@ public class NodeDocument extends Docume
 
         @Override
         public int getMemory() {
-            int size = 8;
+            int size = 114;
             for (String name : childNames) {
-                size += name.length() * 2 + 8;
+                size += name.length() * 2 + 56;
             }
             return size;
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Revision.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Revision.java?rev=1526206&r1=1526205&r2=1526206&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Revision.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/Revision.java
Wed Sep 25 15:29:57 2013
@@ -57,11 +57,6 @@ public class Revision {
      */
     private final boolean branch;
     
-    /**
-     * The string representation.
-     */
-    private String string;
-    
     public Revision(long timestamp, int counter, int clusterId) {
         this(timestamp, counter, clusterId, false);
     }
@@ -166,17 +161,8 @@ public class Revision {
     
     @Override
     public String toString() {
-        if (string == null) {
-            string = new StringBuilder(branch ? "b" : "").
-                append('r').
-                append(Long.toHexString(timestamp)).
-                append('-').
-                append(Integer.toHexString(counter)).
-                append('-').
-                append(Integer.toHexString(clusterId)).
-                toString();
-        }
-        return string;
+        return (branch ? "b" : "") + 'r' + Long.toHexString(timestamp) + '-' +
+                Integer.toHexString(counter) + '-' + Integer.toHexString(clusterId);
     }
     
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/Utils.java?rev=1526206&r1=1526205&r2=1526206&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/Utils.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/util/Utils.java
Wed Sep 25 15:29:57 2013
@@ -69,23 +69,31 @@ public class Utils {
         int size = 0;
 
         for (Entry<?, Object> e : map.entrySet()) {
-            size += e.getKey().toString().length() * 2;
+            if (e.getKey() instanceof Revision) {
+                size += 32;
+            } else {
+                size += 48 + e.getKey().toString().length() * 2;
+            }
             Object o = e.getValue();
             if (o instanceof String) {
-                size += ((String) o).length() * 2;
+                size += 48 + ((String) o).length() * 2;
             } else if (o instanceof Long) {
-                size += 8;
+                size += 16;
             } else if (o instanceof Integer) {
-                size += 4;
+                size += 8;
             } else if (o instanceof Map) {
                 size += 8 + estimateMemoryUsage((Map<String, Object>) o);
             }
         }
 
         if (map instanceof BasicDBObject) {
-            // Based on emperical testing using JAMM
+            // Based on empirical testing using JAMM
             size += 176;
-            size += map.entrySet().size() * 136;
+            size += map.size() * 136;
+        } else {
+            // overhead for some other kind of map
+            size += 112; // TreeMap (80) + unmodifiable wrapper (32)
+            size += map.size() * 64; // 64 bytes per entry
         }
         return size;
     }



Mime
View raw message