From 800cbc0ccfa0c71131b73c788662ab9fa1d0bb2a Mon Sep 17 00:00:00 2001 From: Alec Grieser Date: Tue, 11 Jul 2017 19:32:24 -0700 Subject: [PATCH] added perf tests in python and java for single key get ranges --- .../foundationdb/test/PerformanceTester.java | 17 ++++++++++++++++- tests/python_tests/python_performance.py | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/bindings/java/src-completable/test/com/apple/cie/foundationdb/test/PerformanceTester.java b/bindings/java/src-completable/test/com/apple/cie/foundationdb/test/PerformanceTester.java index 041bbb7cd0..562f6831c9 100644 --- a/bindings/java/src-completable/test/com/apple/cie/foundationdb/test/PerformanceTester.java +++ b/bindings/java/src-completable/test/com/apple/cie/foundationdb/test/PerformanceTester.java @@ -25,7 +25,6 @@ import com.apple.cie.foundationdb.KeySelector; import com.apple.cie.foundationdb.Transaction; import com.apple.cie.foundationdb.TransactionContext; import com.apple.cie.foundationdb.async.AsyncUtil; -import com.apple.cie.foundationdb.subspace.Subspace; import com.apple.cie.foundationdb.tuple.ByteArrayUtil; import java.util.ArrayList; @@ -62,6 +61,7 @@ public class PerformanceTester extends AbstractTester { SERIAL_GET("Java Completable API serial get throughput"), GET_RANGE("Java Completable API get_range throughput"), GET_KEY("Java Completable API get_key throughput"), + GET_SINGLE_KEY_RANGE("Java Completable API get_single_key_range throughput"), ALTERNATING_GET_SET("Java Completable API alternating get and set throughput"), WRITE_TRANSACTION("Java Completable API single-key transaction throughput"); @@ -109,6 +109,7 @@ public class PerformanceTester extends AbstractTester { Tests.SERIAL_GET.setFunction(db -> serialGet(db, 2_000)); Tests.GET_RANGE.setFunction(db -> getRange(db, 1_000)); Tests.GET_KEY.setFunction(db -> getKey(db, 2_000)); + Tests.GET_SINGLE_KEY_RANGE.setFunction(db -> getSingleKeyRange(db, 2_000)); Tests.ALTERNATING_GET_SET.setFunction(db -> alternatingGetSet(db, 2_000)); Tests.WRITE_TRANSACTION.setFunction(db -> writeTransaction(db, 1_000)); } @@ -345,6 +346,20 @@ public class PerformanceTester extends AbstractTester { }); } + public Double getSingleKeyRange(TransactionContext tcx, int count) { + return tcx.run(tr -> { + tr.options().setRetryLimit(5); + long start = System.nanoTime(); + for (int i = 0; i < count; i++) { + int keyIndex = randomKeyIndex(); + tr.getRange(key(keyIndex), key(keyIndex + 1)).asList().join(); + } + long end = System.nanoTime(); + + return count*1_000_000_000.0/(end - start); + }); + } + public Double writeTransaction(TransactionContext tcx, int count) { long start = System.nanoTime(); for (int i = 0; i < count; i++) { diff --git a/tests/python_tests/python_performance.py b/tests/python_tests/python_performance.py index bb22aa24df..8595f5b816 100755 --- a/tests/python_tests/python_performance.py +++ b/tests/python_tests/python_performance.py @@ -47,6 +47,7 @@ class PythonPerformance(PythonTest): 'serial_get' : 'Python API serial get throughput', 'get_range' : 'Python API get_range throughput', 'get_key' : 'Python API get_key throughput', + 'get_single_key_range' : 'Python API get_single_key_range throughput', 'alternating_get_set' : 'Python API alternating get and set throughput', 'write_transaction' : 'Python API single-key transaction throughput', } @@ -267,6 +268,17 @@ class PythonPerformance(PythonTest): return count / (time.time() - s) + @fdb.transactional + def run_get_single_key_range(self, tr, count=2000): + tr.options.set_retry_limit(5) + s = time.time() + + for i in range(count): + index = random.randint(0, self.key_count) + list(tr[self.key(index):self.key(index+1)]) + + return count / (time.time() - s) + @fdb.transactional def single_set(self, tr): key = self.random_key()