Skip to content

Commit

Permalink
Merge pull request #29 from rikvdh/master
Browse files Browse the repository at this point in the history
Fix another degradation, CPU maxes out when POLLOUT is set
  • Loading branch information
c-rack committed May 27, 2015
2 parents 1d18b39 + b5a00b7 commit 7b786b2
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ int zmq::proxy (
int more;
size_t moresz;
zmq_pollitem_t items [] = {
{ frontend_, 0, ZMQ_POLLIN | ZMQ_POLLOUT, 0 },
{ backend_, 0, ZMQ_POLLIN | ZMQ_POLLOUT, 0 },
{ frontend_, 0, ZMQ_POLLIN, 0 },
{ backend_, 0, ZMQ_POLLIN, 0 },
{ control_, 0, ZMQ_POLLIN, 0 }
};
int qt_poll_items = (control_ ? 3 : 2);
zmq_pollitem_t itemsout [] = {
{ frontend_, 0, ZMQ_POLLOUT, 0 },
{ backend_, 0, ZMQ_POLLOUT, 0 }
};

// Proxy can be in these three states
enum {
Expand All @@ -127,6 +131,12 @@ int zmq::proxy (
if (unlikely (rc < 0))
return -1;

// Get the pollout separately because when combining this with pollin it maxes the CPU
// because pollout shall most of the time return directly
rc = zmq_poll (&itemsout [0], 2, 0);
if (unlikely (rc < 0))
return -1;

// Process a control command if any
if (control_ && items [2].revents & ZMQ_POLLIN) {
rc = control_->recv (&msg, 0);
Expand Down Expand Up @@ -160,15 +170,15 @@ int zmq::proxy (
// Process a request
if (state == active
&& items [0].revents & ZMQ_POLLIN
&& items [1].revents & ZMQ_POLLOUT) {
&& itemsout [1].revents & ZMQ_POLLOUT) {
rc = forward(frontend_, backend_, capture_,msg);
if (unlikely (rc < 0))
return -1;
}
// Process a reply
if (state == active
&& items [1].revents & ZMQ_POLLIN
&& items [0].revents & ZMQ_POLLOUT) {
&& itemsout [0].revents & ZMQ_POLLOUT) {
rc = forward(backend_, frontend_, capture_,msg);
if (unlikely (rc < 0))
return -1;
Expand Down

0 comments on commit 7b786b2

Please sign in to comment.