mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
benchmark: timing pht insert operations
This commit is contained in:
1 parent
0b232b1604
commit
a5e3597e68
4 files changed
+37
-12
No files matched your search
@@ -160,6 +160,7 @@ if __name__ == '__main__':
|
||||
featureArgs.add_argument('--pht', action='store_true', default=False,
|
||||
help='Launches PHT benchmark test. '\
|
||||
'Available args for "-t" are: insert. '\
|
||||
'Timer available by adding "timer" to "-o" args'\
|
||||
'Use "-m" option for fixing number of keys to create during the test.')
|
||||
featureArgs.add_argument('--data-persistence', action='store_true', default=0,
|
||||
help='Launches data persistence benchmark test. '\
|
||||
|
||||
@@ -33,6 +33,24 @@ Mbit_format = FuncFormatter(lambda x, pos: '%1.1f' % (x*1024**-2) + 'Mb')
|
||||
def random_hash():
|
||||
return InfoHash(''.join(random.SystemRandom().choice(string.hexdigits) for _ in range(40)).encode())
|
||||
|
||||
def timer(f, *args):
|
||||
"""
|
||||
Start a timer which count time taken for execute function f
|
||||
|
||||
@param f : Function to time
|
||||
@type f : function
|
||||
|
||||
@param args : Arguments of the function f
|
||||
@type args : list
|
||||
|
||||
@rtype : timer
|
||||
@return : Time taken by the function f
|
||||
"""
|
||||
start = time.time()
|
||||
f(*args)
|
||||
|
||||
return time.time() - start
|
||||
|
||||
def reset_before_test(featureTestMethod):
|
||||
"""
|
||||
This is a decorator for all test methods needing reset().
|
||||
@@ -160,7 +178,6 @@ class FeatureTest(object):
|
||||
def run(self):
|
||||
raise NotImplementedError('This method must be implemented.')
|
||||
|
||||
|
||||
##################################
|
||||
# PHT #
|
||||
##################################
|
||||
@@ -189,6 +206,7 @@ class PhtTest(FeatureTest):
|
||||
"""
|
||||
super(PhtTest, self).__init__(test, workbench)
|
||||
self._num_keys = opts['num_keys'] if 'num_keys' in opts else 32
|
||||
self._timer = True if 'timer' in opts else False
|
||||
|
||||
def _reset(self):
|
||||
super(PhtTest, self)._reset()
|
||||
@@ -278,14 +296,18 @@ class PhtTest(FeatureTest):
|
||||
for key in keys:
|
||||
PhtTest.key = key
|
||||
with FeatureTest.lock:
|
||||
pht.insert(key, IndexValue(random_hash()), PhtTest.insertDoneCb)
|
||||
time_taken = timer(pht.insert, key, IndexValue(random_hash()), PhtTest.insertDoneCb)
|
||||
if self._timer:
|
||||
DhtNetwork.log('This insert step took : ', time_taken, 'second')
|
||||
FeatureTest.lock.wait()
|
||||
|
||||
# Recover entries now that the trie is complete.
|
||||
for key in keys:
|
||||
PhtTest.key = key
|
||||
with FeatureTest.lock:
|
||||
pht.lookup(key, PhtTest.lookupCb, PhtTest.lookupDoneCb)
|
||||
time_taken = timer(pht.lookup, key, PhtTest.lookupCb, PhtTest.lookupDoneCb)
|
||||
if self._timer:
|
||||
DhtNetwork.log('This lookup step took : ', time_taken, 'second')
|
||||
FeatureTest.lock.wait()
|
||||
|
||||
all_entries[PhtTest.prefix] = [e.__str__()
|
||||
@@ -296,7 +318,6 @@ class PhtTest(FeatureTest):
|
||||
DhtNetwork.log(all_entries[p])
|
||||
PhtTest.drawTrie(all_entries)
|
||||
|
||||
|
||||
##################################
|
||||
# DHT #
|
||||
##################################
|
||||
@@ -372,7 +393,6 @@ class DhtFeatureTest(FeatureTest):
|
||||
for n in DhtFeatureTest.foreignNodes:
|
||||
nodes.add(n)
|
||||
|
||||
|
||||
class PersistenceTest(DhtFeatureTest):
|
||||
"""
|
||||
This tests persistence of data on the network.
|
||||
@@ -676,7 +696,7 @@ class PersistenceTest(DhtFeatureTest):
|
||||
|
||||
hashes = []
|
||||
|
||||
# Generating considerable amount of values of size 1KB.
|
||||
# Generating considerable amount of values of size 1KB.
|
||||
VALUE_SIZE = 1024
|
||||
NUM_VALUES = self._num_values if self._num_values else 50
|
||||
values = [Value(''.join(random.choice(string.hexdigits) for _ in range(VALUE_SIZE)).encode()) for _ in range(NUM_VALUES)]
|
||||
|
||||
Reference in new issue
Block a user