我试图弄清楚为什么qperf
报告延迟(单向)x
,而REQ / REP(往返)报告类似4x
的情况。我需要做任何特定的套接字调整吗?因为如果我只是打开套接字,则设置TCP_NODELAY(默认情况下在ZMQ中设置)会导致延迟(对于1k缓冲区)非常接近qperf
报告的数字。但是ZMQ落后这些数字大约4-5倍
ZMQ服务器
zmq::context_t context;
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
while (true) {
zmq::message_t request;
// Wait for next request from client
socket.recv(&request);
// Send reply back to client
zmq::message_t reply(5);
memcpy(reply.data(), "World", 5);
socket.send(reply);
}
ZMQ客户端
zmq::context_t context;
zmq::socket_t socket(context, ZMQ_REQ);
std::cout << "Connecting to hello world server…" << std::endl;
socket.connect("tcp://my.host:5555");
const size_t cycles = 100'000;
double throughput = 0;
zmq::message_t reply;
auto start = std::chrono::high_resolution_clock::now();
vector<uint8_t> buff(MessageSize, 0);
for (auto i = 0ul; i < cycles; ++i) {
zmq::message_t request(MessageSize);
memcpy(request.data(), buff.data(), MessageSize);
throughput += request.size();
socket.send(request);
// Get the reply.
socket.recv(&reply);
}
auto end = std::chrono::high_resolution_clock::now();
auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
std::cout << "Latency: " << us / cycles << "us." << std::endl;
std::cout << "Througput: " << std::fixed << throughput / us * 1'000'000 / 1024 / 1024 << "MiB/s." << std::endl;
本质上,这两个都是ZMQ示例http://zguide.zeromq.org/cpp:hwclient
由vcpkg
提供的某些背景,Linux,Ubuntu,GCC 7.3,静态库是在本地构建的,好像它们是从github上获取母版一样。