Reputation: 135
I am facing a memory leakage issue while using czmq library for a simple PUB / SUB
application. So, here is the description:
The setup contains multiple publishers and multiple subscribers. Each publisher and subscriber is a separate thread. Threads are normal POSIX threads on a Linux machine. I am sending messages from the publisher to subscriber using zmsg_send
and zframe
. Each message containing one frame each. I am able to send and receive messages, but over time I am seeing memory occupied by the application increases. I am using tcp pub-sub sockets.
One thing I would like to mention is that after sending the message I am not destroying it as it is mentioned in the documentation that it will.destroy them after sending successfully. While receiving the message I copy the received message into a local structure and then I destroy the frame and zmsg. I am using zpoller to wait on the socket for messages. It's running on an arm processor. Could anyone please guide me towards, what things I need to keep in mind to avoid the memory leakage? The Application sends messages at the rate of 10 Hz.
And clue on the general mistakes that I might be making will be helpful. Thanks.
Upvotes: 0
Views: 676
Reputation: 1042
You need to dig further to work out what is leaking the memory.
Run your application under valgrind
, once you are at the point you think the memory is being leaked, break the execution and valgrind
should report all possible leaks. Hopefully the real leak should stand out as it will be large and obvious.
Other things to try would be reducing the HWM
's to 1 for all sockets and see if that makes a difference. It could be that the memory leak is just ZeroMQ using the buffers (set by HWM
). Linux will not always return the memory to the heap if its freed unless it is needed elsewhere.
Finally thanks to ZeroMQ's architecture you could very easily split your application into two, then your PUB
and SUB
would be separate and narrow down the leak further.
Upvotes: 1