mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
benchmark: timing pht insert operations
This commit is contained in:
1 parent
33fae1cb66
commit
041e280bde
4 files changed
+37
-13
No files matched your search
@@ -200,7 +200,7 @@ private:
|
||||
curr_node = std::make_shared<Node>();
|
||||
root_ = curr_node;
|
||||
}
|
||||
|
||||
|
||||
curr_node->last_reply = now;
|
||||
|
||||
/* Iterate through all bit of the Blob */
|
||||
@@ -209,7 +209,7 @@ private:
|
||||
/* According to the bit define which node is the next one */
|
||||
auto& next = ( p.isActivBit(i) ) ? curr_node->right_child : curr_node->left_child;
|
||||
|
||||
/**
|
||||
/**
|
||||
* If lock, node exists
|
||||
* else create it
|
||||
*/
|
||||
@@ -239,7 +239,7 @@ private:
|
||||
int lookup(const Prefix& p) {
|
||||
int pos = 0;
|
||||
auto now = clock::now(), last_node_time = now;
|
||||
|
||||
|
||||
/* Before lookup remove the useless one [i.e. too old] */
|
||||
while ( leaves_.size() > 0 && leaves_.begin()->first + NODE_EXPIRE_TIME < now ) {
|
||||
leaves_.erase(leaves_.begin());
|
||||
@@ -264,11 +264,11 @@ private:
|
||||
|
||||
if ( pos > 0 ) {
|
||||
auto to_erase = leaves_.find(last_node_time);
|
||||
if ( to_erase != leaves_.end() )
|
||||
if ( to_erase != leaves_.end() )
|
||||
leaves_.erase( to_erase );
|
||||
|
||||
leaves_.emplace( std::move(now), std::move(curr_node) );
|
||||
}
|
||||
}
|
||||
|
||||
return --pos;
|
||||
}
|
||||
|
||||
@@ -171,6 +171,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. '\
|
||||
|
||||
@@ -49,6 +49,24 @@ def random_hash():
|
||||
"""
|
||||
return InfoHash(random_str_val(size=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().
|
||||
@@ -191,7 +209,6 @@ class FeatureTest(object):
|
||||
def run(self):
|
||||
raise NotImplementedError('This method must be implemented.')
|
||||
|
||||
|
||||
##################################
|
||||
# PHT #
|
||||
##################################
|
||||
@@ -220,6 +237,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()
|
||||
@@ -309,14 +327,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__()
|
||||
@@ -327,7 +349,6 @@ class PhtTest(FeatureTest):
|
||||
DhtNetwork.log(all_entries[p])
|
||||
PhtTest.drawTrie(all_entries)
|
||||
|
||||
|
||||
##################################
|
||||
# DHT #
|
||||
##################################
|
||||
@@ -403,7 +424,6 @@ class DhtFeatureTest(FeatureTest):
|
||||
for n in DhtFeatureTest.foreignNodes:
|
||||
nodes.add(n)
|
||||
|
||||
|
||||
class PersistenceTest(DhtFeatureTest):
|
||||
"""
|
||||
This tests persistence of data on the network.
|
||||
@@ -748,8 +768,7 @@ class PersistenceTest(DhtFeatureTest):
|
||||
|
||||
hashes = []
|
||||
|
||||
# Generating considerable amount of values of size 1KB.
|
||||
# TODO: Utiliser fonction _initialSetOfValues.
|
||||
# Generating considerable amount of values of size 1KB.
|
||||
VALUE_SIZE = 1024
|
||||
NUM_VALUES = self._num_values if self._num_values else 50
|
||||
values = [Value(random_str_val(size=VALUE_SIZE).encode()) for _ in range(NUM_VALUES)]
|
||||
|
||||
+5
-1
@@ -276,10 +276,14 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, dht::indexa
|
||||
}
|
||||
std::cout << "Pht::lookup: done." << std::endl;
|
||||
},
|
||||
[](bool ok) {
|
||||
[start](bool ok) {
|
||||
if (not ok) {
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user