[nanomsg] Re: Scatter Gather IO

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Fri, 20 Sep 2013 07:26:47 +0200

Hi David,

(I am new to the nanomsg codebase, so forgive me if these don't make
sense...)

In my application I have a use case when I have a messgage that comes
from lots of small pieces.

My understanding was that this is an ideal scenario for a writev style
scatter IO.

When I looked deeper in the nn_sendmsg implementation I realized that it
copies the iov buffers together and it sends the whole message from this
new buffer.

The sending of the message is asynchronous (it's physically pushed to the kernel space after the nn_sendmsg() call returns to the user. That means that it has to copy the data, otherwise the user could deallocate the buffer before it is actually sent.

The only way to avoid copying is to use NN_MSG option in combination with nn_allocmsg() and nn_freemsg(). However, when sending a nn_allocmsg-allocated memory chunk via nn_sendmsg(), the s/g array is allowed to have at most 1 item.

I am happy to experiment/implement scatter style IO (without copying) if
you think it worst the effort.

If you are interested in this kind of functionality, you should look at supporting s/g arrays in combination with NN_MSG-style messages. If so, you would have to look at internal nn_chunkref object and modify it in such a way that it contains a pointer to the next chunk, so that it's a list of chunks rather than a single chunk passed up and down the stack. You would also have to modify individual transports to account for the change.

Martin

Other related posts: