[zeromq-dev] It occupied my high cpu about 50% when ZeroMQ-3.0.0 version have replaced 2.1.7 version.

Pieter Hintjens ph at imatix.com
Wed Aug 10 16:42:55 CEST 2011


Hi,

Can you make an issue at http://zeromq.jira.com, and attach the test case?

You're running on Windows, right? On Linux the problem doesn't happen.
So if you can debug the loop and see what's wrong, we can make a patch
for you to test.

Cheers
Pieter

On Wed, Aug 10, 2011 at 12:16 PM, SunCan <suncan at szcomtop.com> wrote:
> When I used zeromq-2.1.7 version, everything was fine. I create a listening
> server.
>
> But My cpu was occupied about 50%.
>
> I tracked the source code.
>
> I found prior version that the socket is in blocking mode.
>
> mailbox.cpp
>
> int zmq::mailbox_t::recv (command_t *cmd_, bool block_)
>
> {       //other code
>
>
>
>          int nbytes = ::recv (r, (char *)cmd_, sizeof (command_t), 0);
>
>
>
> //other code
>
>
>
> }
>
> The next version that the code is in “while” circuit whick make program
> constantly loop, it ate my resource.:p
>
> socket_base.cpp
>
> int zmq::socket_base_t::recv (msg_t *msg_, int flags_)
>
> {
>
> //other code
>
>
>
> while (true) {
>
>         if (unlikely (process_commands (block ? timeout : 0, false) != 0))
>
>             return -1;
>
>         rc = xrecv (msg_, flags_);
>
>         if (rc == 0) {
>
>             ticks = 0;
>
>             break;
>
>         }
>
>         if (unlikely (errno != EAGAIN))
>
>             return -1;
>
>         block = true;
>
>         if (timeout > 0) {
>
>             timeout = (int) (end - clock.now_ms ());
>
>             if (timeout <= 0) {
>
>                 errno = EAGAIN;
>
>                 return -1;
>
>             }
>
>         }
>
> }
>
>
>
> //other code
>
>
>
> }
>
>
>
> example:
>
> int main (void)
>
> {
>
>     void *context = zmq_init (1);
>
>     //  Socket to talk to clients
>
>     void *responder = zmq_socket (context, ZMQ_REP);
>
>     int i = zmq_bind (responder, "tcp://*:5555");
>
>     printf ("bind done %d" , i);
>
>     while (1) {
>
>         //  Wait for next request from client
>
>         zmq_msg_t request;
>
>         zmq_msg_init (&request);
>
>         zmq_recv (responder, &request, 0);//version 3.0.0 use
> zmq_recvmsg(responder, &request, 0)
>
>         printf ("Received Hello\n");
>
>         zmq_msg_close (&request);
>
>         //  Do some 'work'
>
>         Sleep (1);
>
>
>
>         //  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;
>
> }
>
> Can u suggest me the right way to do so?
>
>
>
> Best regards.
>
> Thanks.
>
>
>
>
>
>
>
>
>
>
>
>
>
> suncan
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>



More information about the zeromq-dev mailing list