[zeromq-dev] Ever growing memory even with HWM
Nam-Luc Tran
namluc.tran at euranova.eu
Fri Jun 24 17:38:07 CEST 2011
Hello everyone,
Following is a simple publisher-subscriber java code, which represents
the behaviour of one of our applications. When we launch the publisher
on one machine and five subscribers on an other machine, memory on the
publisher side keep growing and growing until eventually crashing.
I believe we are in the "slow subscriber case" described in the
zguide.
My first question is: isn't the publisher by default (no semi
transient socket) supposed to drop every message if the subscriber is
not ready? So where could that memory growing come from?
I have also tried with setting an identity to the subscriber and a HWM
on the publisher as described in the zguide but the same memory
problem occurs.
We use zeromq 2.1.7 with the latest stable java bindings on Ubuntu
10.04 64bits.
Any help will be appreciated,
Nam-Luc Tran
/////Publisher code/////
package com.ena.zmq;
import org.zeromq.ZMQ;
public class PubClient {
public static void main(String[] args) {
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket publisher = context.socket(ZMQ.PUB);
publisher.bind("tcp://*:5800");
publisher.setHWM(20);
byte[] msg = new byte[5000];
msg[msg.length-1]=0;
System.out.println("Publisher online");
while(true){
publisher.send(msg,0);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
////Subscriber code////
package com.ena.zmq;
import org.zeromq.ZMQ;
public class SubClient {
public static void main(String[] args) {
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket subscriber = context.socket(ZMQ.SUB);
subscriber.connect("tcp://192.168.0.27:5800");
subscriber.setIdentity("Hello".getBytes());
subscriber.subscribe("".getBytes());
byte[] msg;
System.out.println("Subscriber connected");
while(true){
msg = subscriber.recv(0);
while(subscriber.hasReceiveMore()) {
msg = subscriber.recv(0);
}
try { //workload simulationThread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110624/efdf749a/attachment.htm>
More information about the zeromq-dev
mailing list