[zeromq-dev] any examples of using downstream/upstream sockets?
anton at angri.ru
anton at angri.ru
Sun Mar 28 10:01:33 CEST 2010
2010/3/28 Martin Sustrik <sustrik at 250bpm.com>:
> Hi Anton,
>
>> Thank you for the great library, it seems it fits my needs well and
>> it's performance is amazing!
>>
>> I've played with req/rep socket pair a bit and everything seems to be
>> ok with them. But I've found no examples of using DOWNSTREAM/UPSTREAM
>> sockets
>
> http://github.com/sustrik/cppbutterfly
Ok, it compiles (after adding #include <stdlib.h>). And how to use it?
:) What does it do?
> http://github.com/sustrik/jbutterfly
>
>> (I'm especially interested in C and Python bindings). So I've
>> just took zeromq-2.0.6/perf/local_lat.c and k
>> zeromq-2.0.6/perf/remote_lat.c, changed socket types there and removed
>> send() part of the loop from UPSTREAM side and recv() from DOWNSTREAM.
>>
>> Unfortunatelly, it seems it's not enough. Upstream side does not
>> always quit after runing downstream one with the same amount of
>> messages to transmit. Sometimes upstream side recieves message with
>> zero length. Sometimes downstream side crashes with message "No such
>> file or directory
>> rc != -1 (epoll.cpp:83)" (I'm using linux 2.6.33 x86-64)
>>
>> And probably the most bad thing is that downstream side looks like
>> everything is ok when upstream one is not even running! It reports
>> that average latency is about 0.1 us. I'd love to see such latency if
>> it really works.
>
> Nope. There were several reports of such a behaviour. Unfortunately, I
> haven't been able to reproduce it yet :( Can you pass your test program?
>
> Martin
>
Here is the simple python code which demonstrates that downstream
sockets feel okay without upstream ones:
#!/usr/bin/env python
import time
import zmq
MSGS = 1000
def main():
ctx = zmq.Context()
s = ctx.socket(zmq.DOWNSTREAM)
s.connect('tcp://127.0.0.1:5000')
start = time.time()
for i in xrange(MSGS):
s.send('message%i' % i)
elapsed = (time.time() - start) * (10 ** 6)
print 'sent %i messages in %.3f us' % (MSGS, elapsed)
if __name__ == '__main__':
main()
I've tried to add sleep() right before closing a socket, run
downstreamer, go ahead to this sleep (when all messages go away) and
run upstreamer after that. No luck: it receives no messages. Is such
behaviour (similar to pub/sub) expected with downstream/upstream?
More information about the zeromq-dev
mailing list