ahanikel commented on code in PR #1155:
URL: https://github.com/apache/jackrabbit-oak/pull/1155#discussion_r1376238274
##########
oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/CachingDataStoreTest.java:
##########
@@ -638,4 +644,41 @@ private void waitFinish() {
e.printStackTrace();
}
}
+
+ @Test
+ public void performanceGetRecordIfStored() throws Exception {
+ tear();
+ final int iterations = 100;
+ final long backendResponseDelay = 4L;
+
+ final File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
+ final String id = getIdForInputStream(f);
+ final DataIdentifier di = new DataIdentifier(id);
+
+ init(1, 64 * 1024 * 1024, 10, 0L, backendResponseDelay);
+ // we write directly to the backend because that's the situation we
have in a shared remote datastore:
+ // the file was already written by a different datastore but isn't
present in the datastore.cache.
+ backend.write(di, f);
+
+ long start = System.nanoTime();
+ for (int i = 0; i < iterations; ++i) {
+ LOG.trace("" + dataStore.getRecordIfStored(di)); // LOG.trace to
avoid the call being optimised away
+ }
+ long timeUncached = System.nanoTime() - start;
+
+ tear();
+
+ init(1, 64 * 1024 * 1024, 10, 10000L, backendResponseDelay);
+ // we write directly to the backend because that's the situation we
have in a shared remote datastore:
+ // the file was already written by a different datastore but isn't
present in the datastore.cache.
+ backend.write(di, f);
+
+ start = System.nanoTime();
+ for (int i = 0; i < iterations; ++i) {
+ LOG.trace("" + dataStore.getRecordIfStored(di)); // LOG.trace to
avoid the call being optimised away
+ }
+ long timeCached = System.nanoTime() - start;
+
Review Comment:
Yes, I wanted to "prove" the effectiveness of the cache but although I've
only checked for a 5x improvement where the difference should be at least 100x
for that test case, I agree it is still fragile and should be avoided.
I've changed the test to only check that the record is in the cache after
the first access, and to ensure that it is loaded from the cache when accessed
a second time. Is that what you meant?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]