Skip to content
Snippets Groups Projects
Commit a5e3597e authored by kaldoran's avatar kaldoran Committed by Adrien Béraud
Browse files

benchmark: timing pht insert operations

parent 0b232b16
Branches
No related tags found
No related merge requests found
...@@ -160,6 +160,7 @@ if __name__ == '__main__': ...@@ -160,6 +160,7 @@ if __name__ == '__main__':
featureArgs.add_argument('--pht', action='store_true', default=False, featureArgs.add_argument('--pht', action='store_true', default=False,
help='Launches PHT benchmark test. '\ help='Launches PHT benchmark test. '\
'Available args for "-t" are: insert. '\ '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.') 'Use "-m" option for fixing number of keys to create during the test.')
featureArgs.add_argument('--data-persistence', action='store_true', default=0, featureArgs.add_argument('--data-persistence', action='store_true', default=0,
help='Launches data persistence benchmark test. '\ help='Launches data persistence benchmark test. '\
......
...@@ -33,6 +33,24 @@ Mbit_format = FuncFormatter(lambda x, pos: '%1.1f' % (x*1024**-2) + 'Mb') ...@@ -33,6 +33,24 @@ Mbit_format = FuncFormatter(lambda x, pos: '%1.1f' % (x*1024**-2) + 'Mb')
def random_hash(): def random_hash():
return InfoHash(''.join(random.SystemRandom().choice(string.hexdigits) for _ in range(40)).encode()) 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): def reset_before_test(featureTestMethod):
""" """
This is a decorator for all test methods needing reset(). This is a decorator for all test methods needing reset().
...@@ -160,7 +178,6 @@ class FeatureTest(object): ...@@ -160,7 +178,6 @@ class FeatureTest(object):
def run(self): def run(self):
raise NotImplementedError('This method must be implemented.') raise NotImplementedError('This method must be implemented.')
################################## ##################################
# PHT # # PHT #
################################## ##################################
...@@ -189,6 +206,7 @@ class PhtTest(FeatureTest): ...@@ -189,6 +206,7 @@ class PhtTest(FeatureTest):
""" """
super(PhtTest, self).__init__(test, workbench) super(PhtTest, self).__init__(test, workbench)
self._num_keys = opts['num_keys'] if 'num_keys' in opts else 32 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): def _reset(self):
super(PhtTest, self)._reset() super(PhtTest, self)._reset()
...@@ -278,14 +296,18 @@ class PhtTest(FeatureTest): ...@@ -278,14 +296,18 @@ class PhtTest(FeatureTest):
for key in keys: for key in keys:
PhtTest.key = key PhtTest.key = key
with FeatureTest.lock: 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() FeatureTest.lock.wait()
# Recover entries now that the trie is complete. # Recover entries now that the trie is complete.
for key in keys: for key in keys:
PhtTest.key = key PhtTest.key = key
with FeatureTest.lock: 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() FeatureTest.lock.wait()
all_entries[PhtTest.prefix] = [e.__str__() all_entries[PhtTest.prefix] = [e.__str__()
...@@ -296,7 +318,6 @@ class PhtTest(FeatureTest): ...@@ -296,7 +318,6 @@ class PhtTest(FeatureTest):
DhtNetwork.log(all_entries[p]) DhtNetwork.log(all_entries[p])
PhtTest.drawTrie(all_entries) PhtTest.drawTrie(all_entries)
################################## ##################################
# DHT # # DHT #
################################## ##################################
...@@ -372,7 +393,6 @@ class DhtFeatureTest(FeatureTest): ...@@ -372,7 +393,6 @@ class DhtFeatureTest(FeatureTest):
for n in DhtFeatureTest.foreignNodes: for n in DhtFeatureTest.foreignNodes:
nodes.add(n) nodes.add(n)
class PersistenceTest(DhtFeatureTest): class PersistenceTest(DhtFeatureTest):
""" """
This tests persistence of data on the network. This tests persistence of data on the network.
......
...@@ -259,10 +259,14 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, dht::indexa ...@@ -259,10 +259,14 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, dht::indexa
} }
std::cout << "Pht::lookup: done." << std::endl; std::cout << "Pht::lookup: done." << std::endl;
}, },
[](bool ok) { [start](bool ok) {
if (not ok) { if (not ok) {
std::cout << "Pht::lookup: dht Get failed." << std::endl; std::cout << "Pht::lookup: dht Get failed." << std::endl;
} }
auto end = std::chrono::high_resolution_clock::now();
std::cout << "Pht::lookup: took " << print_dt(end-start) << "s)" << std::endl;
}, exact_match.size() != 0 and exact_match == "false" ? false : true }, exact_match.size() != 0 and exact_match == "false" ? false : true
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment