-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_thr.py
78 lines (57 loc) · 1.84 KB
/
local_thr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# coding: utf-8
# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.
#
# Some original test code Copyright (c) 2007-2010 iMatix Corporation,
# Used under LGPLv3
import sys
import time
import zmq
from parse_args import parse_args
def local_thr(url, count, size, poll, copy):
"""recv a bunch of messages on a PULL socket
Should be started before `pusher`
"""
ctx = zmq.Context()
s = ctx.socket(zmq.PULL)
# Add your socket options here.
# For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
if poll:
p = zmq.Poller()
p.register(s)
s.bind(url)
watch = zmq.Stopwatch()
block = zmq.NOBLOCK if poll else 0
# Wait for the other side to connect.
msg = s.recv()
assert len(msg) == size
watch.start()
for i in range(count - 1):
if poll:
res = p.poll()
msg = s.recv(block, copy=copy)
if i % 150 == 0:
sys.stdout.write('.')
sys.stdout.flush()
elapsed = watch.stop()
if elapsed == 0:
elapsed = 1
throughput = (1e6 * float(count)) / float(elapsed)
megabits = float(throughput * size * 8) / 1e6
print ("\nDone.")
print ("message size : %8i [B]" % (size,))
print ("message count : %8i [msgs]" % (count,))
print ("mean throughput: %8.0f [msg/s]" % (throughput,))
print ("mean throughput: %12.3f [Mb/s]" % (megabits,))
print ("test time : %12.3f [s]" % (elapsed * 1e-6,))
def main():
args = parse_args()
print ("Running program...")
tic = time.time()
local_thr(args.url, args.count, args.size, args.poll, args.copy)
toc = time.time()
if (toc - tic) < 3:
print ("For best results, tests should take at least a few seconds.")
if __name__ == '__main__':
main()