26
use_poll = '-p' in sys.argv
27
use_copy = '-c' in sys.argv
26
use_poll = '-p' in argv
27
use_copy = '-c' in argv
33
if len(sys.argv) != 4:
34
print 'usage: remote_lat [-c use-copy] [-p use-poll] <connect-to> <message-size> <roundtrip-count>'
34
print ('usage: remote_lat [-c use-copy] [-p use-poll] <connect-to> <message-size> <roundtrip-count>')
38
connect_to = sys.argv[1]
39
message_size = int(sys.argv[2])
40
roundtrip_count = int(sys.argv[3])
41
except (ValueError, OverflowError), e:
42
print 'message-size and message-count must be integers'
39
message_size = int(argv[2])
40
roundtrip_count = int(argv[3])
41
except (ValueError, OverflowError):
42
print ('message-size and message-count must be integers')
45
45
ctx = zmq.Context()
46
46
s = ctx.socket(zmq.REQ)
47
s.setsockopt(zmq.LINGER, -1)
48
49
s.connect(connect_to)
54
msg = ' ' * message_size
54
# remove the b for Python2.5:
55
msg = b' ' * message_size
56
clock = zmq.Stopwatch()
57
watch = zmq.Stopwatch()
59
# start = time.clock()
60
block = zmq.NOBLOCK if use_poll else 0
61
64
for i in range (0, roundtrip_count):
64
67
assert(res[0][1] & zmq.POLLOUT)
65
s.send(msg, zmq.NOBLOCK if use_poll else 0, copy=use_copy)
68
s.send(msg, block, copy=use_copy)
69
72
assert(res[0][1] & zmq.POLLIN)
70
msg = s.recv(zmq.NOBLOCK if use_poll else 0, copy=use_copy)
73
msg = s.recv(block, copy=use_copy)
71
75
assert len (msg) == message_size
78
elapsed = (end - start)
79
# elapsed = (end - start) * 1000000 # use with time.clock
77
elapsed = watch.stop()
79
# remove the b for Python2.5:
80
t = s.send(b'done', copy=False, track=True)
80
83
latency = elapsed / (roundtrip_count * 2)
82
print "message size: %.0f [B]" % (message_size, )
83
print "roundtrip count: %.0f" % (roundtrip_count, )
84
print "mean latency: %.3f [us]" % (latency, )
85
print ("message size: %i [B]" % (message_size, ))
86
print ("roundtrip count: %i" % (roundtrip_count, ))
87
print ("mean latency: %.3f [us]" % (latency, ))
86
# Let the context finish messaging before ending.
87
# You may need to increase this time for longer or many messages.
90
93
if __name__ == "__main__":