You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2015/08/12 17:55:42 UTC
svn commit: r1695561 - in /jackrabbit/oak/branches/1.2: ./
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/
oak-core/src/test/java/org/apache/jackrabbit/oak/plugi...
Author: mreutegg
Date: Wed Aug 12 15:55:42 2015
New Revision: 1695561
URL: http://svn.apache.org/r1695561
Log:
OAK-3199: DocumentNodeState ignores binary value for memory calculation
Merge revision 1695540 from trunk
Modified:
jackrabbit/oak/branches/1.2/ (props changed)
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java
Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 12 15:55:42 2015
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673713,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678124,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680172,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868
,1685023,1685075,1685370,1685552,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688634,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689831,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941,1691139,1691151,1691159,1691167,1691183,1691188,1691210,1691280,1691307,1691331-1691333,1691345,1691384-1691385,1691401,1691509,1692133-1692134,1692156,1692250,1692274,1692363,1692382,1692478,1692955,1693002,1693030,1693209,1693421,1693525-1693526,1694007,1694393-1694394,1695050,1695122,1695280,1695299,1695457,1695482,1695507,1695521
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673713,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678124,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680172,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868
,1685023,1685075,1685370,1685552,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688634,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689831,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941,1691139,1691151,1691159,1691167,1691183,1691188,1691210,1691280,1691307,1691331-1691333,1691345,1691384-1691385,1691401,1691509,1692133-1692134,1692156,1692250,1692274,1692363,1692382,1692478,1692955,1693002,1693030,1693209,1693421,1693525-1693526,1694007,1694393-1694394,1695050,1695122,1695280,1695299,1695457,1695482,1695507,1695521,1695540
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java?rev=1695561&r1=1695560&r2=1695561&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java Wed Aug 12 15:55:42 2015
@@ -56,6 +56,7 @@ import com.google.common.collect.Iterabl
import com.google.common.collect.Iterators;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.plugins.document.util.Utils.estimateMemoryUsage;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
/**
@@ -375,6 +376,8 @@ public class DocumentNodeState extends A
PropertyState prop = properties.get(propertyName);
if (prop == null) {
return null;
+ } else if (prop instanceof DocumentPropertyState) {
+ return ((DocumentPropertyState) prop).getValue();
}
JsopBuilder builder = new JsopBuilder();
new JsonSerializer(builder, store.getBlobSerializer()).serialize(prop);
@@ -448,15 +451,14 @@ public class DocumentNodeState extends A
@Override
public int getMemory() {
- int size = 212 + path.length() * 2;
+ int size = 164 + estimateMemoryUsage(path);
// rough approximation for properties
for (Map.Entry<String, PropertyState> entry : properties.entrySet()) {
// name
- size += 48 + entry.getKey().length() * 2;
+ size += estimateMemoryUsage(entry.getKey());
PropertyState propState = entry.getValue();
if (propState.getType() != Type.BINARY
&& propState.getType() != Type.BINARIES) {
- // assume binaries go into blob store
for (int i = 0; i < propState.count(); i++) {
// size() returns length of string
// overhead:
@@ -464,6 +466,12 @@ public class DocumentNodeState extends A
// - 48 bytes per string
size += 56 + propState.size(i) * 2;
}
+ } else {
+ // calculate size based on blobId value
+ // referencing the binary in the blob store
+ // double the size because the parsed PropertyState
+ // will have a similarly sized blobId as well
+ size += estimateMemoryUsage(getPropertyAsString(entry.getKey())) * 2;
}
}
return size;
@@ -602,7 +610,7 @@ public class DocumentNodeState extends A
if (!children.isEmpty()) {
size = 114;
for (String c : children) {
- size += c.length() * 2 + 56;
+ size += estimateMemoryUsage(c) + 8;
}
}
cachedMemory = size;
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java?rev=1695561&r1=1695560&r2=1695561&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java Wed Aug 12 15:55:42 2015
@@ -102,6 +102,17 @@ final class DocumentPropertyState implem
return parsed().count();
}
+ /**
+ * Returns the raw un-parsed value as passed to the constructor of this
+ * property state.
+ *
+ * @return the raw un-parsed value.
+ */
+ @Nonnull
+ String getValue() {
+ return value;
+ }
+
//------------------------------------------------------------< Object >--
@Override
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java?rev=1695561&r1=1695560&r2=1695561&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java Wed Aug 12 15:55:42 2015
@@ -137,11 +137,11 @@ public class Utils {
if (e.getKey() instanceof Revision) {
size += 32;
} else {
- size += 48 + e.getKey().toString().length() * 2;
+ size += estimateMemoryUsage(e.getKey().toString());
}
Object o = e.getValue();
if (o instanceof String) {
- size += 48 + ((String) o).length() * 2;
+ size += estimateMemoryUsage((String) o);
} else if (o instanceof Long) {
size += 16;
} else if (o instanceof Boolean) {
@@ -172,6 +172,16 @@ public class Utils {
}
/**
+ * Estimates the memory usage of the given string.
+ *
+ * @param s the string to estimate.
+ * @return the estimated memory usage.
+ */
+ public static int estimateMemoryUsage(String s) {
+ return 48 + s.length() * 2;
+ }
+
+ /**
* Generate a unique cluster id, similar to the machine id field in MongoDB ObjectId objects.
*
* @return the unique machine id
Modified: jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java?rev=1695561&r1=1695560&r2=1695561&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java Wed Aug 12 15:55:42 2015
@@ -24,8 +24,14 @@ import java.util.concurrent.Callable;
import com.mongodb.BasicDBObject;
+import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.plugins.document.util.RevisionsKey;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.apache.jackrabbit.oak.plugins.memory.BinaryPropertyState;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.junit.Test;
/**
@@ -41,6 +47,22 @@ public class MeasureMemory {
static final DocumentNodeStore STORE = new DocumentMK.Builder()
.setAsyncDelay(0).getNodeStore();
+ static final Blob BLOB;
+ static final String BLOB_VALUE;
+
+ static {
+ try {
+ BLOB = STORE.createBlob(new RandomStream(1024 * 1024, 42));
+ NodeBuilder builder = STORE.getRoot().builder();
+ builder.child("binary").setProperty(new BinaryPropertyState("b", BLOB));
+ STORE.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+ NodeState n = STORE.getRoot().getChildNode("binary");
+ BLOB_VALUE = ((DocumentNodeState) n).getPropertyAsString("b");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
@Test
public void overhead() throws Exception {
measureMemory(new Callable<Object[]>() {
@@ -129,6 +151,17 @@ public class MeasureMemory {
}
@Test
+ public void nodeWithBinaryProperty() throws Exception {
+ measureMemory(new Callable<Object[]>() {
+ @Override
+ public Object[] call() {
+ DocumentNodeState n = generateNodeWithBinaryProperties(3);
+ return new Object[]{n, n.getMemory() + OVERHEAD};
+ }
+ });
+ }
+
+ @Test
public void revisionsKey() throws Exception {
measureMemory(new Callable<Object[]>() {
@Override
@@ -176,6 +209,14 @@ public class MeasureMemory {
return n;
}
+ static DocumentNodeState generateNodeWithBinaryProperties(int propertyCount) {
+ DocumentNodeState n = generateNode(0);
+ for (int i = 0; i < propertyCount; i++) {
+ n.setProperty("binary" + i, new String(BLOB_VALUE));
+ }
+ return n;
+ }
+
static BasicDBObject generateBasicObject(int propertyCount) {
BasicDBObject n = new BasicDBObject(new String("_id"), new String(
"/hello/world"));