【发布时间】:2017-05-24 19:48:07
【问题描述】:
我正在试验 ZeroMQ,我有一个 PUSH 应用程序,它发送约 370,000 条消息,每条消息大小为 10Kb。
context = zmq.Context()
socket = context.socket( zmq.PUSH )
socket.bind( "tcp://127.0.0.1:5557" )
no_msgs = 0
i = 370000
fd = open( "input_text_files/file1.txt", 'r' )
msg = fd.read()
while i > 0:
print "Sending data of size" , len( msg )
rc = socket.send( msg )
no_msgs += 1
if rc == None:
print True
if rc == -1:
print "ERROR!!"
i = i-1
PULL 应用程序刚刚循环接收消息:
context = zmq.Context()
socket = context.socket( zmq.PULL )
socket.connect( "tcp://127.0.0.1:5557" )
no_msgs = 1
i = 1
while True:
msg = socket.recv()
no_msgs += 1
print "Received msg", i
print "Received %s" %( len( msg ) )
i = i + 1
使用此设置,有消息丢失,即PULL 套接字没有收到所有 370,000 条消息。我在PUSH 套接字上添加了socket.hwm = 10,并且收到了所有370,000 条消息。有人可以向我解释这是如何工作的吗?
【问题讨论】:
-
你在哪一侧添加了 socket.hwm ,拉还是推?
-
@somdoron 在推动方面