mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-06 13:21:10 +01:00
Proxy performance fix, ticket #3439
Improve performance of the proxy forwarding batch of message. Add throughput benchmark for proxy. Fix valgrind error reported on unitialized vars RELICENSE: Add emtr grant
This commit is contained in:
@@ -116,40 +116,49 @@ int forward (class zmq::socket_base_t *from_,
|
||||
class zmq::socket_base_t *capture_,
|
||||
zmq::msg_t *msg_)
|
||||
{
|
||||
int more;
|
||||
size_t moresz;
|
||||
size_t complete_msg_size = 0;
|
||||
while (true) {
|
||||
int rc = from_->recv (msg_, 0);
|
||||
if (unlikely (rc < 0))
|
||||
return -1;
|
||||
// Forward a burst of messages
|
||||
for (unsigned int i = 0; i < zmq::proxy_burst_size; i++) {
|
||||
int more;
|
||||
size_t moresz;
|
||||
size_t complete_msg_size = 0;
|
||||
|
||||
complete_msg_size += msg_->size ();
|
||||
// Forward all the parts of one message
|
||||
while (true) {
|
||||
int rc = from_->recv (msg_, ZMQ_DONTWAIT);
|
||||
if (rc < 0) {
|
||||
if (likely (errno == EAGAIN && i > 0))
|
||||
return 0; // End of burst
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
moresz = sizeof more;
|
||||
rc = from_->getsockopt (ZMQ_RCVMORE, &more, &moresz);
|
||||
if (unlikely (rc < 0))
|
||||
return -1;
|
||||
complete_msg_size += msg_->size ();
|
||||
|
||||
// Copy message to capture socket if any
|
||||
rc = capture (capture_, msg_, more);
|
||||
if (unlikely (rc < 0))
|
||||
return -1;
|
||||
moresz = sizeof more;
|
||||
rc = from_->getsockopt (ZMQ_RCVMORE, &more, &moresz);
|
||||
if (unlikely (rc < 0))
|
||||
return -1;
|
||||
|
||||
rc = to_->send (msg_, more ? ZMQ_SNDMORE : 0);
|
||||
if (unlikely (rc < 0))
|
||||
return -1;
|
||||
// Copy message to capture socket if any
|
||||
rc = capture (capture_, msg_, more);
|
||||
if (unlikely (rc < 0))
|
||||
return -1;
|
||||
|
||||
if (more == 0)
|
||||
break;
|
||||
rc = to_->send (msg_, more ? ZMQ_SNDMORE : 0);
|
||||
if (unlikely (rc < 0))
|
||||
return -1;
|
||||
|
||||
if (more == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
// A multipart message counts as 1 packet:
|
||||
from_stats_->msg_in++;
|
||||
from_stats_->bytes_in += complete_msg_size;
|
||||
to_stats_->msg_out++;
|
||||
to_stats_->bytes_out += complete_msg_size;
|
||||
}
|
||||
|
||||
// A multipart message counts as 1 packet:
|
||||
from_stats_->msg_in++;
|
||||
from_stats_->bytes_in += complete_msg_size;
|
||||
to_stats_->msg_out++;
|
||||
to_stats_->bytes_out += complete_msg_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user