Quantcast
Channel: Active questions tagged zeromq - Stack Overflow
Viewing all articles
Browse latest Browse all 193

Measuring zmq latency between two python processes in high resolution in windows 10

$
0
0

I want to measure the latency of zeromq between two python processes in high resolution(in a us/ns unit)(windows 10).

Here's my code.

sub.py

import sysimport zmqimport timeport = "5556"if len(sys.argv) > 1:    port =  sys.argv[1]    int(port)if len(sys.argv) > 2:    port1 =  sys.argv[2]    int(port1)# Socket to talk to servercontext = zmq.Context()socket = context.socket(zmq.SUB)print('connecting to publisher')socket.connect ("tcp://localhost:%s" % port)if len(sys.argv) > 2:    socket.connect ("tcp://localhost:%s" % port1)topicfilter = "10001"socket.setsockopt_string(zmq.SUBSCRIBE, topicfilter)total_value = 0while True:    string = socket.recv()    got_time = time.time() # resolution in windows 10: 15.6ms    topic, msgdata = string.split()    dur = got_time - float(msgdata)    print('it took %.5fms from pub' % (dur*1000))

pub.py

import zmqimport randomimport sysimport timeport = "5556"if len(sys.argv) > 1:    port =  sys.argv[1]    int(port)context = zmq.Context()socket = context.socket(zmq.PUB)socket.bind("tcp://*:%s" % port)topic = 10001while True:    msgdata = time.time() # resolution in windows 10: 15.6ms    socket.send_string("%d %.5f" % (topic, msgdata))    print("topic:%d, msg:%.5f" % (topic, msgdata))    time.sleep(1)

However, since time.time() function's resolution in windows 10 is only 15.6ms(windows default timer period), I was unable to measure the latency below 15.6ms with code.

So I thought about using time.perf_counter() function, which have microsecond resolution, but it was also useless in measuring time difference of two process since time.perf_counter() function's reference point is undefined according to doc.

Is there any other way to measure the time difference between two python processes in high resolution(microsecond or nanosecond unit)?


Viewing all articles
Browse latest Browse all 193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>