我正在努力实现一致<500 us latency on my ZMQ REQ/REP application. However, I've encountered 2 types of delay.
我可以部分理解自初始连接程序等以来的第一个数据包延迟。但是,我无法理解随机延迟。对于问题的上下文,我的应用程序只有 1 个服务器和 1 个客户端。客户端和服务器在我的本地运行。我用 C++ 开发了它。我想了解 REQ/REP 是否适合我的情况,或者我是否遗漏了什么。我写了一个示例 python 脚本来复制这个问题。下面给出Python代码,
客户
import zmq
import time
from random import randbytes
port = "5556"
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:%s" % port)
val = randbytes(200000)
while True:
st = time.time()
message = socket.send(val)
socket.recv()
ed = time.time()
took = (ed - st)*1000000 # us
if took > 400:
print(took)
服务员
import zmq
import time
port = "5556"
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:%s" % port)
while True:
st = time.time()
message = socket.recv()
socket.send(b"World from")
ed = time.time()
took = (ed - st)*1000000 #us
if took > 200:
print(took)
我试过的
有没有人遇到过类似的事情?
注意:此问题与硬件无关。我已经在不同的硬件上试过了。如果您的结果与我的不同,请告诉我。