-
Notifications
You must be signed in to change notification settings - Fork 172
benchmark: fix pht insert test #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,7 +187,13 @@ cdef extern from "opendht/indexation/pht.h" namespace "dht::indexation": | |
cdef cppclass Prefix: | ||
Prefix() except + | ||
Prefix(vector[uint8_t]) except + | ||
Prefix(vector[uint8_t], size_t first) except + | ||
Prefix(Prefix& p) except + | ||
string toString() const | ||
string flagsToString() const | ||
size_t size_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO fields should not be exposed here. Even in the C++ code, these fields are only public for convenience but should be made private, since it's dangerous to manipulate them directly (risk of inconsistence, like edit: this refers to lines 194-196 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agreed with that, since flags_ and content_ are internal variable, user shouldn't be able to edit them directly. |
||
vector[uint8_t] flags_ | ||
vector[uint8_t] content_ | ||
ctypedef pair[InfoHash, uint64_t] IndexValue "dht::indexation::Value" | ||
ctypedef map[string, vector[uint8_t]] IndexKey "dht::indexation::Pht::Key" | ||
ctypedef map[string, uint32_t] IndexKeySpec "dht::indexation::Pht::KeySpec" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,21 +249,22 @@ def _reset(self): | |
@staticmethod | ||
def lookupCb(vals, prefix): | ||
PhtTest.indexEntries = list(vals) | ||
PhtTest.prefix = prefix.decode() | ||
DhtNetwork.log('Index name: <todo>') | ||
DhtNetwork.log('Leaf prefix:', prefix) | ||
PhtTest.prefix = str(prefix) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the goal of this patch is to "fix" the pht test, please also make it use non-static callbacks and fields so we can run multiple instances at the same time. Current design is awful. |
||
# TODO: output index name | ||
# DhtNetwork.Log.log('Index name: <todo>') | ||
DhtNetwork.Log.log('Leaf prefix:', PhtTest.prefix) | ||
for v in vals: | ||
DhtNetwork.log('[ENTRY]:', v) | ||
DhtNetwork.Log.log('[ENTRY]:', v) | ||
|
||
@staticmethod | ||
def lookupDoneCb(ok): | ||
DhtNetwork.log('[LOOKUP]:', PhtTest.key, "--", "success!" if ok else "Fail...") | ||
DhtNetwork.Log.log('[LOOKUP]:', PhtTest.key, "--", "success!" if ok else "Fail...") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log.log, looks like "a lot" of "Log" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kaldoran: What do you mean precisely? Do you suggest changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, in order to avoid future mistake. [Log.debug or some other form] |
||
with FeatureTest.lock: | ||
FeatureTest.lock.notify() | ||
|
||
@staticmethod | ||
def insertDoneCb(ok): | ||
DhtNetwork.log('[INSERT]:', PhtTest.key, "--", "success!" if ok else "Fail...") | ||
DhtNetwork.Log.log('[INSERT]:', PhtTest.key, "--", "success!" if ok else "Fail...") | ||
with FeatureTest.lock: | ||
FeatureTest.lock.notify() | ||
|
||
|
@@ -323,10 +324,8 @@ def _insertTest(self): | |
keyspec = collections.OrderedDict([('foo', NUM_DIG)]) | ||
pht = Pht(b'foo_index', keyspec, dht) | ||
|
||
DhtNetwork.log('PHT has', | ||
pht.MAX_NODE_ENTRY_COUNT, | ||
'node'+ ('s' if pht.MAX_NODE_ENTRY_COUNT > 1 else ''), | ||
'per leaf bucket.') | ||
DhtNetwork.Log.log('PHT has %s entr%s per leaf bucket.' % | ||
(pht.MAX_NODE_ENTRY_COUNT, 'ies' if pht.MAX_NODE_ENTRY_COUNT > 1 else 'y')) | ||
keys = [{ | ||
[_ for _ in keyspec.keys()][0] : | ||
''.join(random.SystemRandom().choice(string.hexdigits) | ||
|
@@ -340,7 +339,7 @@ def _insertTest(self): | |
with FeatureTest.lock: | ||
time_taken = timer(pht.insert, key, IndexValue(random_hash()), PhtTest.insertDoneCb) | ||
if self._timer: | ||
DhtNetwork.log('This insert step took : ', time_taken, 'second') | ||
DhtNetwork.Log.log('This insert step took : ', time_taken, 'second') | ||
FeatureTest.lock.wait() | ||
|
||
time.sleep(1) | ||
|
@@ -351,15 +350,17 @@ def _insertTest(self): | |
with FeatureTest.lock: | ||
time_taken = timer(pht.lookup, key, PhtTest.lookupCb, PhtTest.lookupDoneCb) | ||
if self._timer: | ||
DhtNetwork.log('This lookup step took : ', time_taken, 'second') | ||
DhtNetwork.Log.log('This lookup step took : ', time_taken, 'second') | ||
FeatureTest.lock.wait() | ||
|
||
all_entries[PhtTest.prefix] = [e.__str__() | ||
for e in PhtTest.indexEntries] | ||
if PhtTest.prefix not in all_entries.keys(): | ||
all_entries[PhtTest.prefix] = [] | ||
all_entries[PhtTest.prefix].extend([e.__str__() for e in PhtTest.indexEntries]) | ||
|
||
for p in all_entries.keys(): | ||
DhtNetwork.log('All entries under prefix', p, ':') | ||
DhtNetwork.log(all_entries[p]) | ||
DhtNetwork.Log.log('All entries under prefix', p, ':') | ||
for e in all_entries[p]: | ||
DhtNetwork.Log.log(e) | ||
PhtTest.drawTrie(all_entries) | ||
|
||
################################## | ||
|
@@ -496,7 +497,7 @@ def _trigger_dp(self, trigger_nodes, _hash, count=1): | |
n.run(config=config) | ||
n.bootstrap(self._bootstrap.ip4, | ||
str(self._bootstrap.port)) | ||
DhtNetwork.log('Node','['+_hash_str+']', | ||
DhtNetwork.Log.log('Node','['+_hash_str+']', | ||
'started around', _hash.toString().decode() | ||
if n.isRunning() else | ||
'failed to start...' | ||
|
@@ -536,6 +537,7 @@ def run(self): | |
else: | ||
raise NameError("This test is not defined '" + self._test + "'") | ||
except Exception as e: | ||
DhtNetwork.Log.err('Unexpected error') | ||
traceback.print_tb(e.__traceback__) | ||
print(type(e).__name__+':', e, file=sys.stderr) | ||
finally: | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just cpp.Prefix (like for InfoHash and others) ? __cinit__can be used for initialization. The API doesn't make use of shared_ptr<Prefix>