我正在使用 ZeroMQ 3.2.3 和 CZmq 1.4.1。我尝试了“Hello world”示例。该示例(https://github.com/imatix/zguide/tree/master/examples/C)在使用 10 个并发客户端时,允许我在 Intel i7(总共 8 GB RAM)上每秒最多交换 12500 条消息本地主机(Ubuntu 13.04)上的 8 个内核)。
我读过 ZeroMQ 可以处理更多。我做错了什么,还是错过了什么?
这是示例代码:
// Hello World server
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
int main (void)
{
// Socket to talk to clients
void *context = zmq_ctx_new ();
void *responder = zmq_socket (context, ZMQ_REP);
int rc = zmq_bind (responder, "tcp://*:5555");
assert (rc == 0);
while (1) {
char buffer [10];
zmq_recv (responder, buffer, 10, 0);
//printf ("Received Hello\n");
zmq_send (responder, "World", 5, 0);
//usleep (1); // Do some 'work'
}
return 0;
}
// Hello World client
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
int main (void)
{
printf ("Connecting to hello world server...\n");
void *context = zmq_ctx_new ();
void *requester = zmq_socket (context, ZMQ_REQ);
zmq_connect (requester, "tcp://localhost:5555");
int request_nbr;
for (request_nbr = 0; request_nbr != 100000; request_nbr++) {
char buffer [10];
// printf ("Sending Hello %d...\n", request_nbr);
zmq_send (requester, "Hello", 5, 0);
zmq_recv (requester, buffer, 10, 0);
// printf ("Received World %d\n", request_nbr);
}
zmq_close (requester);
zmq_ctx_destroy (context);
return 0;
}
谢谢 !