[zeromq-dev] transmission rate of broker is less than 5000req/s

Elwin.Gao elwin.gao4444 at gmail.com
Tue Aug 21 11:41:01 CEST 2012


Pieter Hintjens <ph <at> imatix.com> writes:

> 
> Elwin,
> 
> Please provide the source of your two examples on a pastebin so we can
> see what you're actually doing, thanks.
> 
> -Pieter
> 

there are three files, this is the example of A Request-Reply Broker in zmq
official guide, then delete all printf() and sleep(), that all.

rrclient.c : 

#include "zhelpers.h"                                                           
int main (void) 
{
        void *context = zmq_init (1);

        //  Socket to talk to server
        void *requester = zmq_socket (context, ZMQ_REQ);
        zmq_connect (requester, "tcp://localhost:5559");

        uint64_t start = s_clock();
        int request_nbr;
        for (request_nbr = 0; request_nbr != 10000; request_nbr++) {
                s_send (requester, "Hello");
                char *string = s_recv (requester);
//              printf ("Received reply %d [%s]\n", request_nbr, string);
                free (string);
        }
        uint64_t end = s_clock();
        uint64_t diff = end - start;
        printf("Using time: %2lu:%04lu\n", diff/1000, diff%1000);
        zmq_close (requester);
        zmq_term (context);
        return 0;
}  

rrserver.c : 

#include "zhelpers.h"
int main (void) 
{
        void *context = zmq_init (1);
                                                                                
        //  Socket to talk to clients
        void *responder = zmq_socket (context, ZMQ_REP);
        zmq_connect (responder, "tcp://localhost:5560");

        while (1) {
                //  Wait for next request from client
                char *string = s_recv (responder);
//              printf ("Received request: [%s]\n", string);
                free (string);

                //  Do some 'work'
//              sleep (1);

                //  Send reply back to client
                s_send (responder, "World");
        }
        //  We never get here but clean up anyhow
        zmq_close (responder);
        zmq_term (context);
        return 0;
}                                                                               

rrbroker : 

#include "zhelpers.h"                                                           
int main (void) 
{
        //  Prepare our context and sockets
        void *context = zmq_init (1);
        void *frontend = zmq_socket (context, ZMQ_ROUTER);
        void *backend  = zmq_socket (context, ZMQ_DEALER);
        zmq_bind (frontend, "tcp://*:5559");
        zmq_bind (backend,  "tcp://*:5560");

        //  Initialize poll set
        zmq_pollitem_t items [] = {
                { frontend, 0, ZMQ_POLLIN, 0 },
                { backend,  0, ZMQ_POLLIN, 0 }
        };
        //  Switch messages between sockets
        while (1) {
                zmq_msg_t message;
                int64_t more;           //  Multipart detection
                zmq_poll (items, 2, -1);
                if (items [0].revents & ZMQ_POLLIN) {
                        while (1) {
                                //  Process all parts of the message
                                zmq_msg_init (&message);
                                zmq_recv (frontend, &message, 0);
                                size_t more_size = sizeof (more);
                                zmq_getsockopt (frontend, ZMQ_RCVMORE,
                                                &more, &more_size);
                                zmq_send (backend, &message,
                                                more? ZMQ_SNDMORE: 0);
                                zmq_msg_close (&message);
                                if (!more)
                                        break;      //  Last message part
                        }
                }
                if (items [1].revents & ZMQ_POLLIN) {
                        while (1) {
                                //  Process all parts of the message
                                zmq_msg_init (&message);
                                zmq_recv (backend, &message, 0);
                                size_t more_size = sizeof (more);
                                zmq_getsockopt (backend, ZMQ_RCVMORE,
                                                &more, &more_size);
                                zmq_send (frontend, &message,
                                                more? ZMQ_SNDMORE: 0);
                                zmq_msg_close (&message);
                                if (!more)
                                        break;      //  Last message part
                        }
                }
        }
        //  We never get here but clean up anyhow
        zmq_close (frontend);
        zmq_close (backend);
        zmq_term (context);
        return 0;
}                                                                               






More information about the zeromq-dev mailing list