[zeromq-dev] prevent msg caching

Whit Armstrong armstrong.whit at gmail.com
Wed Sep 28 14:31:04 CEST 2011


Ah,  I see.  I clearly didn't read the man page thoroughly.

I modified the code to use HWM=1, but the sender still manages to send
more than 10 messages even if I only call zmq_recv once on the PULL
socket.

Any thoughts on this?  Is it possible that the messages are batched
and sent before the sender realizes that the receiver is at the HWM.

Can someone point me towards debugging flags (if available)?

(code below without headers)

-Whit

// vent.c
int main (void)
{
    void *context = zmq_init (1);
    void *sender = zmq_socket (context, ZMQ_PUSH);
    uint64_t hwm = 1;
    zmq_setsockopt (sender, ZMQ_HWM, &hwm, sizeof (hwm));
    uint64_t swap = 0;
    zmq_setsockopt (sender, ZMQ_SWAP, &swap, sizeof (swap));
    zmq_bind (sender, "tcp://*:5557");

    size_t msg_counter = 0;
    while(1) {
        zmq_msg_t msg;
        zmq_msg_init_size (&msg, 5);
        memcpy (zmq_msg_data (&msg), "World", 5);
        zmq_send (sender, &msg, 0);
        zmq_msg_close (&msg);
        msg_counter+=1;
        printf ("%lu\n",msg_counter);
        fflush (stdout);
    }
    zmq_close (sender);
    zmq_term (context);
    return 0;
}

// worker.c
int main (void)
{
    void *context = zmq_init (1);
    printf ("*\n");
    fflush (stdout);

    void *receiver = zmq_socket (context, ZMQ_PULL);
    uint64_t hwm = 1;
    zmq_setsockopt (receiver, ZMQ_HWM, &hwm, sizeof (hwm));
    uint64_t swap = 0;
    zmq_setsockopt (receiver, ZMQ_SWAP, &swap, sizeof (swap));
    zmq_connect (receiver, "tcp://localhost:5557");

    zmq_msg_t msg;
    zmq_msg_init (&msg);
    zmq_recv (receiver, &msg, 0);
    zmq_msg_close (&msg);

    printf (".\n");
    fflush (stdout);

    zmq_close (receiver);
    zmq_term (context);
    return 0;
}




On Tue, Sep 27, 2011 at 10:42 PM, Chuck Remes <cremes.devlist at mac.com> wrote:
>
> On Sep 27, 2011, at 9:09 PM, Whit Armstrong wrote:
>
>> I'm testing an R package for zmq.
>>
>> I'm using push/pull and I would like to prevent messages from being
>> cached at the receiver while I'm debugging the package.
>>
>> I've tried the following:
>>
>>    uint64_t hwm = 0;
>>    zmq_setsockopt (receiver, ZMQ_HWM, &hwm, sizeof (hwm));
>>
>>    uint64_t swap = 0;
>>    zmq_setsockopt (receiver, ZMQ_SWAP, &swap, sizeof (swap));
>>
>> However, as soon as I call zmq_connect on the pull socket (the
>> receiver), the push socket sends 100s of messages before I even make
>> the first call to zmq_recv.  If I let the app run without calling
>> zmq_recv at all on the pull socket I can see the memory slowly build
>> on the receiver process.
>>
>> So, my question is what other zmq options (or kernel options) do I
>> need to set to prevent the sender from sending (and prevent the
>> receiver from caching) while I debug the app?
>
> The default value of 0 means "no limit."
>
> http://api.zeromq.org/2-1:zmq-setsockopt
>
> Try setting it to 1.
>
> cr
>
> _______________________________________________
> 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