[zeromq-dev] Why sub receive the pub's data have a long delay(5~10s) in pub/sub mode?

lgf gaofenglihao at 126.com
Fri Jul 4 06:03:00 CEST 2014


Hello,


I would like to realize something similar to a real radio broadcast:


pub/sub:
- a publisher distributes packets of information
- subscribers receive real-time and process information


but in my case timing is very important; to keep the radio analogy:


- all subscribers receive the same information pretty much at the same time (real-time)
- if a subscriber stops listening for a few seconds, it loses some words but does not lose synchronization with others (when he starts listening again, he's where every one else is in the story)


Both of server(pub) and two clients(subA & subB) test on the ARM+linux2.6.39 ,ZMQ_4.0.4.


And the test results like this: 
1) "pub" zmq_send the data("abc") finished at 2014/7/4 11:15:10.
2) then one "subA" will zmq_recv it  5~10 seconds later ,about at 2014/7/4 11:15:15.
3) another "subB" will zmq_recv it  5~10 seconds later ,about at 2014/7/4 11:15:23.
4) test 100+ times all the same like this result.




In my case,I would like to know:
1) Why there is a long delay between pub to subA or subB. ?????????????
2) Why subA and subB cannot receive the pub's data both pretty much at the same time . ?????????????


In my mind, the subA and subB will real-time zmq_recv  it in 1~2 seconds later, about at 2014/7/4 11:15:11 . 


I'm trying to understand whether this is the expected behavior or if indeed there is a problem either with zmq or with my code.


I thought that setting a very low HWM (1) in a publisher-subscriber socket would pretty much solve my problems, but instead I find that HWM is somewhat ignored.




My test code as below :


//pub========================================
int server()
{
...
ctx = zmq_init(1);
rep = zmq_socket(ctx,ZMQ_REP);
pub = zmq_socket(ctx,ZMQ_PUB);


int sndHWM =1;
int rcvHWM =1;
int bufLen = 256;
zmq_setsockopt(sub, ZMQ_SNDHWM,&sndHWM,sizeof(int));
zmq_setsockopt(sub, ZMQ_RCVHWM,&rcvHWM,sizeof(int));
zmq_setsockopt(sub, ZMQ_RCVBUF,&bufLen,sizeof(int));
zmq_setsockopt(sub, ZMQ_SNDBUF,&bufLen,sizeof(int));


zmq_bind(pub,"tcp://192.168.1.11:5555");
...
while(1)
{
...
if(...)// ..."if press some key then send"
{
 s_send(pub,"abc");
}
}
...
}


//subA & subB ======================================
int client()
{
void *context = zmq_init (1); //  Socket to talk to server
void *sub = zmq_socket (context, ZMQ_SUB);


int sndHWM =1;
int rcvHWM =1;
int bufLen = 256;
zmq_setsockopt(sub, ZMQ_SNDHWM,&sndHWM,sizeof(int));
zmq_setsockopt(sub, ZMQ_RCVHWM,&rcvHWM,sizeof(int));
zmq_setsockopt(sub, ZMQ_RCVBUF,&bufLen,sizeof(int));
zmq_setsockopt(sub, ZMQ_SNDBUF,&bufLen,sizeof(int));


zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "",0);


int ret =zmq_connect (sub, "tcp://192.168.1.11:5555");
while(1)
{
...
zmq_pollitem_t items[1];
items[0].socket = sub;
items[0].fd = 0;
items[0].events = ZMQ_POLLIN;


nRet = zmq_poll(items,1,-1);


if(0 == nRet)
{
printf("zmq_poll continue\r\n");
continue;
}




if(items[0].revents > 0)
{
char *contents1 = s_recv (sub);
printf(" contents1 = %d \r\n",contents1);
free (contents1);
}
}


...
}


Anybody would like to help me to understand what's going on here?


Thank you very much!


BestRegards,


//------------------------------------------
Geffery_Lee,
skype   : lgf402
E-mail  : gaofenglihao at 126.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140704/02af81b1/attachment.htm>


More information about the zeromq-dev mailing list