[zeromq-dev] CZMQ: why aren't zframes reference counted?

Pieter Hintjens ph at imatix.com
Mon Sep 1 17:25:23 CEST 2014


OK, a few ideas then. zframe is the wrong level to do reference
counting; it should happen at zmsg or a similar multiframe class.
Second, you are doing your own queuing and acking, so you can design
your own ref counted class on top of zframe. I'd probably not even use
zframe then, use zmq_msg directly.

On Mon, Sep 1, 2014 at 5:11 PM, Goswin von Brederlow <goswin-v-b at web.de> wrote:
> The zmsg_send_keep() would be using ZFRAME_REUSE. I considered that.
>
> But when I send a message to all (or many) peers it gets put into each
> peers outgoing list, prefixed by the peers sequence number, and only
> gets removed when the peer ACKs the message.
>
> Even if I use ZFRAME_REUSE I need a way to know when a message can be
> destroyed. That means either reference counting the message itself or
> using a shallow copy since the underlying zmq_msg_t already reference
> counts (which then means every peer can destory its shallow copy when
> it gets an ACK).
>
> I considered keeping a global list of all pending messages with a list
> of peers that are pending and removing peers from the list as they
> ACK. But that would result in a much more complex code.
>
> On Mon, Sep 01, 2014 at 04:14:44PM +0200, Pieter Hintjens wrote:
>> There is an option on zframe_send (ZFRAME_REUSE) which side-steps the
>> destruction. It's a simple exception that lets you send the same frame
>> many times, without the machinery of reference counting, duplicating,
>> etc.
>>
>> On Mon, Sep 1, 2014 at 2:57 PM, Goswin von Brederlow <goswin-v-b at web.de> wrote:
>> > Hi,
>> >
>> > the zframe_t type is based on the zmq_msg_t type. But while zms_msg_t
>> > uses reference counting there is no function to clone a zframe_t using
>> > a shared zmq_msg_t object. Consequently there is no way to make a
>> > shallow copy of a zmsg_t (which holds a zlist of zframe_t).
>> >
>> > Also sending a zmsg_t is destrutive. I need to send the same message
>> > (except different identity frame at the start) to many peers and
>> > possibly resend it when a peer reconnects. Currently that means
>> > duplicating every message many (100-1000) times which wastes both ram
>> > and cpu a lot.
>> >
>> > Any objections to adding three functions:
>> >
>> > // create new zframe_t that shares the same content as frame
>> > zframe_t * zframe_clone (zframe_t *frame);
>> >
>> > // create new zmsg_t that is a shallow copy of msg
>> > // frame contents are shared, see zframe_clone
>> > zmsg_t * zmsg_shallow_dup (zmsg_t *msg);
>> >
>> > // Send message to socket, but do not destroy after sending.
>> > int zmdg_send_keep (zmsg_t *msg, void *dest);
>> >
>> > MfG
>> >         Goswin
> _______________________________________________
> 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