Skip to content

Instantly share code, notes, and snippets.

@JustAnotherArchivist
Created December 21, 2018 15:03
Show Gist options
  • Save JustAnotherArchivist/94d4987c8d9d7b1527db4cfff18939f0 to your computer and use it in GitHub Desktop.
Save JustAnotherArchivist/94d4987c8d9d7b1527db4cfff18939f0 to your computer and use it in GitHub Desktop.
PySyncObj flushing benchmark for https://github.com/bakwc/PySyncObj/pull/98
diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py
index 10e26f0..a0584cd 100644
--- a/benchmarks/benchmarks.py
+++ b/benchmarks/benchmarks.py
@@ -98,6 +98,6 @@ if __name__ == '__main__':
res = detectMaxRps(200, i)
print('nodes number: %d, rps: %d' % (i, int(res)))
elif mode == 'custom':
- singleBenchmark(25000, 10, 3)
+ singleBenchmark(14000, 10, 3)
else:
printUsage()
diff --git a/benchmarks/testobj.py b/benchmarks/testobj.py
index fd11132..c8f2f20 100644
--- a/benchmarks/testobj.py
+++ b/benchmarks/testobj.py
@@ -2,14 +2,17 @@ from __future__ import print_function
import sys
import time
import random
+import tempfile
+import os.path
+import shutil
from collections import defaultdict
class TestObj(SyncObj):
- def __init__(self, selfNodeAddr, otherNodeAddrs):
- super(TestObj, self).__init__(selfNodeAddr, otherNodeAddrs)
+ def __init__(self, selfNodeAddr, otherNodeAddrs, **kwargs):
+ super(TestObj, self).__init__(selfNodeAddr, otherNodeAddrs, **kwargs)
self.__appliedCommands = 0
@replicated
@@ -49,27 +52,35 @@ if __name__ == '__main__':
selfAddr = None
partners = sys.argv[4:]
- maxCommandsQueueSize = int(0.9 * SyncObjConf().commandsQueueSize / len(partners))
+ tmpdir = tempfile.mkdtemp()
+ print(selfAddr + ': ' + tmpdir)
+ try:
+ conf = SyncObjConf()
+ conf.journalFile = os.path.join(tmpdir, 'journal')
+ conf.flushJournal = True
+ maxCommandsQueueSize = int(0.9 * conf.commandsQueueSize / len(partners))
- obj = TestObj(selfAddr, partners)
+ obj = TestObj(selfAddr, partners, conf = conf)
- while obj._getLeader() is None:
- time.sleep(0.5)
+ while obj._getLeader() is None:
+ time.sleep(0.5)
- time.sleep(4.0)
+ time.sleep(4.0)
- startTime = time.time()
+ startTime = time.time()
- while time.time() - startTime < 25.0:
- st = time.time()
- for i in xrange(0, numCommands):
- obj.testMethod(getRandStr(cmdSize), callback=clbck)
- _g_sent += 1
- delta = time.time() - st
- assert delta <= 1.0
- time.sleep(1.0 - delta)
+ while time.time() - startTime < 25.0:
+ st = time.time()
+ for i in xrange(0, numCommands):
+ obj.testMethod(getRandStr(cmdSize), callback=clbck)
+ _g_sent += 1
+ delta = time.time() - st
+ assert delta <= 1.0
+ time.sleep(1.0 - delta)
- time.sleep(4.0)
+ time.sleep(4.0)
+ finally:
+ shutil.rmtree(tmpdir)
successRate = float(_g_success) / float(_g_sent)
print('SUCCESS RATE:', successRate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment