zeromq/pyzmq — Issue #148: HWM for SUB socket does NOT DROP data
Author: joelkim
Created: 2011-10-19 02:03:43+00:00
State: open

As I understand, hwm setting for SUB socket will drop new data if it reaches queue limit and drop new data.
However, in my test, the queue size of SUB socket does not drop the new data. It just saves all data into the subscriber's queue.

These are my test codes:
= server =========================
import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5556")

count = 0
while True:
count += 1
socket.send("%d" % count)
print count
time.sleep(0.5)

= client =========================
import zmq
import time

seconds = 2

context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.setsockopt(zmq.SUBSCRIBE, "")
socket.setsockopt(zmq.HWM, 2)
socket.connect("tcp://127.0.0.1:5556")

while True:
count = socket.recv()
print count
time.sleep(seconds)

In this test, the subscriber must print jumping numbers because some data are dropped. But it doesn't.