[zeromq-dev] In the high-concurrency env, REQ-REP mode is not fast?
kaka chen
kaka11.chen at gmail.com
Fri Jun 8 08:56:28 CEST 2012
Hi All:
I have tested zeromq 2.1 and 3.2 in my env, found the REQ-REP mode is not
fast in the high-concurrency env, only about 3000 msgs/s, message content
is "hello", 5 bytes, comparing with other programs, such as libevent. I
have read the source code of zeromq 2.1, don't think it has some
performance problems, and the only different point is thread communication
with socketpair messages, not by shared heap memory queue. Does someone
have some idea, and is my test method is right for zeromq? Thanks!
server.cpp:
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main (void)
{
void *context = zmq_init (2);
// Socket to talk to clients
void *responder = zmq_socket (context, ZMQ_REP);
zmq_bind (responder, "tcp://*:5555");
while (1) {
// Wait for next request from client
zmq_msg_t request;
zmq_msg_init (&request);
zmq_recv (responder, &request, 0);
zmq_msg_close (&request);
// Send reply back to client
zmq_msg_t reply;
zmq_msg_init_size (&reply, 5);
memcpy (zmq_msg_data (&reply), "World", 5);
zmq_send (responder, &reply, 0);
zmq_msg_close (&reply);
}
// We never get here but if we did, this would be how we end
zmq_close (responder);
zmq_term (context);
return 0;
}
client.cpp:
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <assert.h>
#define request_num 100
#define clients 500
static void *request_fn(void *arg)
{
void *context = zmq_init (2);
void *requester = zmq_socket (context, ZMQ_REQ);
zmq_connect (requester, "tcp://localhost:5555");
int i;
for (i = 0; i < request_num; ++i)
{
zmq_msg_t request;
zmq_msg_init_size (&request, 5);
memcpy (zmq_msg_data (&request), "Hello", 5);
zmq_send (requester, &request, 0);
zmq_msg_close (&request);
zmq_msg_t reply;
zmq_msg_init (&reply);
zmq_recv (requester, &reply, 0);
zmq_msg_close (&reply);
}
zmq_close (requester);
zmq_term (context);
return NULL;
}
int main (void)
{
pthread_t request_threads[clients];
int i;
for (i = 0; i < clients; ++i)
{
assert(pthread_create(&request_threads[i], 0,
request_fn, NULL) == 0);
}
for (i = 0; i < clients; ++i) {
pthread_join(request_threads[i], NULL);
}
return 0;
}
Kaka Chen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120608/2a3b31fc/attachment.htm>
More information about the zeromq-dev
mailing list