I want to limit the amount of memory consumed by my ZeroMQ message queues in a Python application. I know that setting a label with a high water level will limit the amount that will be queued on the sender side, but is there a way to control how much will be queued on the receiver side? Linking to Python ZeroMQ is like an unlimited amount.
My test case: I have two python terminals that I use for testing. One of them is the receiver:
Python 2.5.1 (r251:54863, Aug 25 2008, 20:50:04) [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import zmq >>> context = zmq.Context() >>> socket = context.socket(zmq.PULL) >>> socket.setsockopt(zmq.RCVBUF, 256) >>> socket.bind("tcp://127.0.0.1:12345")
Another is the sender:
Python 2.5.1 (r251:54863, Aug 25 2008, 20:50:04) [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import zmq >>> context=zmq.Context() >>> socket = context.socket(zmq.PUSH) >>> socket.setsockopt(zmq.SNDBUF, 2048) >>> socket.setsockopt(zmq.HWM, 1) >>> socket.connect("tcp://127.0.0.1:12345") >>> num = 0 >>> while True: ... print num ... socket.send(str(num)) ... num = num + 1 ...
I run socket.recv() on the receiver side a couple of times to make sure the queue is working, but other than that, let the two terminals just sit there. The send cycle never seems to lock, and the receiving message seems to be growing memory.
source share