libzmq: use poll in router dealer pattern, the speed is very slow, why?
Please use this template for reporting suspected bugs or requests for help.
Issue description
I’m writing a simple test program using router dealer pattern as follow.(using c or cppzmq has the same problem)
int main()
{
zmq::context_t context(1);
zmq::socket_t router(context, ZMQ_ROUTER);
router.bind("tcp://*:5555");
zmq::pollitem_t items [] = {
{ router, 0, ZMQ_POLLIN, 0 }
};
int recvCount = 0;
const int maxCount = 10e4;
s_console("start");
while(true)
{
zmq::poll(items, 1, -1);
if (items[0].revents & ZMQ_POLLIN)
{
//nothing todo, just receving
std::string identify = s_recv(router);
std::string msg = s_recv(router);
++recvCount;
if (recvCount == maxCount)
{
s_console("recv %d messages!", maxCount);
break;
}
}
}
}
If I comment the code //zmq::poll(items, 1, -1); // if (items[0].revents & ZMQ_POLLIN) receive 100000 simple string msg using just 200~300ms, but if I add the poll code, receive 100000 msg using 40+ seconds.
where is the problem? Thanks
Environment
- libzmq version (commit hash if unreleased): 4.0.2
- OS: Windows
Minimal test code / Steps to reproduce the issue
as the issue’s description
What’s the actual result? (include assertion message & call stack if applicable)
If I comment the code //zmq::poll(items, 1, -1); // if (items[0].revents & ZMQ_POLLIN) receive 100000 simple string message using just 200~300ms, but if I add the poll code, receive 100000 messages using 40+ seconds.
What’s the expected result?
add zmq::poll(items, 1, -1); if (items[0].revents & ZMQ_POLLIN), and receive 100000 messages using 300 ms, not 40+ seconds.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (12 by maintainers)
Attentione:
All remarks to the performance were based on zmq 4.2.2 release! I just run the client using the latest head version: Good improvement up to 2500 CMD/RESPONSES calls per second.
I stumbled into the same issue: A peer to peer application sending sync CMD/RESPONSE pairs using ROUTER sockets is unsusable slow on windows (czmq zloop reactor design). The application is sending a CMD and then waits for a RESPONSE. Then it sends the next CMD …
Peer to Peer
Linux to Linux : ~5000 CMD/RESPONSE pairs per second Win to Linux : ~200 CMD/RESPONSE pairs per second Win to Win : ~200 CMD/RESPONSE pairs per second Linux to Win : ~450 CMD/RESPONSE pairs per second
ZMQ_DONTWAIT is no help in this usage scenario…