Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
abede1e7
Commit
abede1e7
authored
Jan 24, 2020
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
pingpong: print execution time
parent
859d8dc9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/tools/pingpong.py
+17
-2
17 additions, 2 deletions
python/tools/pingpong.py
with
17 additions
and
2 deletions
python/tools/pingpong.py
+
17
−
2
View file @
abede1e7
...
@@ -35,13 +35,21 @@ pong_node.ping(ping_node.getBound())
...
@@ -35,13 +35,21 @@ pong_node.ping(ping_node.getBound())
loc_ping
=
dht
.
InfoHash
.
get
(
"
toto99
"
)
loc_ping
=
dht
.
InfoHash
.
get
(
"
toto99
"
)
loc_pong
=
dht
.
InfoHash
.
get
(
str
(
loc_ping
))
loc_pong
=
dht
.
InfoHash
.
get
(
str
(
loc_ping
))
net
=
[]
for
i
in
range
(
1
,
10
):
node
=
dht
.
DhtRunner
()
node
.
run
(
config
=
config
)
node
.
ping
(
ping_node
.
getBound
())
net
.
append
(
node
)
i
=
0
i
=
0
MAX
=
2048
MAX
=
2048
loop
=
asyncio
.
get_event_loop
()
loop
=
asyncio
.
get_event_loop
()
def
done
(
h
,
ok
):
def
done
(
h
,
ok
):
print
(
h
,
"
over
"
,
ok
)
pass
#print(h, "over", ok)
def
ping
(
node
,
h
):
def
ping
(
node
,
h
):
global
i
global
i
...
@@ -52,13 +60,20 @@ def ping(node, h):
...
@@ -52,13 +60,20 @@ def ping(node, h):
loop
.
stop
()
loop
.
stop
()
def
pong
(
node
,
h
):
def
pong
(
node
,
h
):
print
(
node
.
getNodeId
().
decode
(),
"
got ping
"
,
h
,
i
)
#
print(node.getNodeId().decode(), "got ping", h, i)
loop
.
call_soon_threadsafe
(
ping
,
node
,
h
)
loop
.
call_soon_threadsafe
(
ping
,
node
,
h
)
return
True
return
True
t1
=
time
.
time
()
ping_node
.
listen
(
loc_ping
,
lambda
v
,
e
:
pong
(
pong_node
,
loc_pong
)
if
not
e
else
True
)
ping_node
.
listen
(
loc_ping
,
lambda
v
,
e
:
pong
(
pong_node
,
loc_pong
)
if
not
e
else
True
)
pong_node
.
listen
(
loc_pong
,
lambda
v
,
e
:
pong
(
ping_node
,
loc_ping
)
if
not
e
else
True
)
pong_node
.
listen
(
loc_pong
,
lambda
v
,
e
:
pong
(
ping_node
,
loc_ping
)
if
not
e
else
True
)
ping
(
pong_node
,
loc_ping
)
ping
(
pong_node
,
loc_ping
)
loop
.
run_forever
()
loop
.
run_forever
()
t2
=
time
.
time
()
print
(
MAX
,
"
ping-pong done, took
"
,
t2
-
t1
,
"
s
"
)
print
(
1000
*
(
t2
-
t1
)
/
MAX
,
"
ms per rt
"
,
MAX
/
(
t2
-
t1
),
"
rt per s
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment