Guys, Thanks a lot! I knew that it had to be something obvious.
Actually, do set linger to 0 in other places where I have to close a socket, but here I was trying to go for re-connect instead and did not realize that it's basically the same situation. It's only when I was reducing the case to be closer to the guide I replaced disconnect()/connect() by destroy()/create()/connect(). It should have rung the bell, but it didn't. Thanks again. Regards, Mykola 2017-11-08 21:31 GMT+02:00 Justin Azoff <[email protected]>: > It's not really the polling that is causing this.... simplifying the > program to this: > > #include <zmq.hpp> > #include <memory> > #include <iostream> > #include <unistd.h> > > int main () { > zmq::context_t context {1}; > std::unique_ptr<zmq::socket_t> socket {new zmq::socket_t{context, > ZMQ_REQ}}; > socket->connect("tcp://localhost:33171"); > > while (true) { > socket->send(zmq::message_t {"test", 4}); > usleep(5000000); > > std::cout << "Timeout!\n"; > socket.reset(new zmq::socket_t{context, ZMQ_REQ}); > socket->connect("tcp://localhost:33171"); > } > > return 0; > } > > and running > > sudo tcpdump -n -i lo dst port 33171 | pv -l > /dev/null > > > shows initially 24 packets/sec, but after a few timeouts, it grows > linearly to 50,75,100,125 packets/sec > > with the timeout of 500ms instead of 5s. it reaches 1000 packets/sec > pretty quickly. > > So, why does it do this? It's because zmq tries to finish sending > what you told it to. In your case, there is a simple fix: disable > linger. > > Simply add a call to > > int linger = 0; > socket->setsockopt (ZMQ_LINGER, &linger, sizeof (linger)); > > before destroying the socket, and your problem will go away. > > On Wed, Nov 8, 2017 at 1:59 PM, Luca Boccassi <[email protected]> > wrote: > > On Wed, 2017-11-08 at 19:59 +0200, Mykola Ostrovskyy via zeromq-dev > > wrote: > >> 2017-11-08 15:54 GMT+02:00 Luca Boccassi <[email protected]>: > >> > >> > > >> > Heartbeats are now included in the protocol, check the various > >> > ZMQ_HEARTBEAT_* socket options > >> > > >> > -- > >> > Kind regards, > >> > Luca Boccassi > >> > > >> > > >> > >> Luca, > >> > >> Thanks for the quick reply. > >> > >> From the first look ZMQ_HEARTBEAT_* stuff is quite different from > >> what I > >> have now. I will investigate more, but it looks like I would need > >> substantial redesign to switch to that. > >> > >> Is there a way to get the pattern described in the guide to work? Or > >> is it > >> explicitly not supposed to work anymore? > >> > >> After all, heart beat implementation is just one use case. > >> Hypothetically, > >> there can be different scenarios where you try to send some data to > >> REP > >> socket, time out waiting for reply, and eventually retrying to send > >> it > >> again. > >> > >> > >> Regards, > >> Mykola > > > > It can work - but don't continuously create and delete sockets, that's > > a known anti-pattern. They are all async operation that happen in the > > background. With such a small poll timeout, the connection might not > > even have been attempted when you destroy the socket. > > > > -- > > Kind regards, > > Luca Boccassi > > > > _______________________________________________ > > zeromq-dev mailing list > > [email protected] > > https://lists.zeromq.org/mailman/listinfo/zeromq-dev > > > > > > -- > - Justin > _______________________________________________ > zeromq-dev mailing list > [email protected] > https://lists.zeromq.org/mailman/listinfo/zeromq-dev >
_______________________________________________ zeromq-dev mailing list [email protected] https://lists.zeromq.org/mailman/listinfo/zeromq-dev
