0

I have been tinkering with an open source project that has started making use of asynchronous overlapped IO for sending data using the Winsock2 interfaces in one of its most recent versions. In the project's past, one approach to improve the send performance of (old) blocking/synchronous IO has been to increase the sendbuffer size (SO_SNDBUF) to the size of the packets to be sent (using the send() function). With the introduction of overlapped IO (using the WSASend() function) this feels less sensible to me. I read the documentation and thought setting SO_SNDBUF to 0 might actually help save some resources but I ended up just slowing down the sending process.

Now, despite some research I could not find any description of how WSASend() and overlapped non-blocking IO actually handles the internal socket buffer. Will it take the provided array of WSABUF structures and push in as much data as it can into the internal send buffer (i.e. multiple WSABUF, some of which might become split) every once in a while? Or will it only try and push a single WSABUF into the buffer (splitting the WSABUF if the internal buffer is too small) at a time?

Taking it from there: How reasonable is it to increase the SO_SNDBUF to the size of the largest WSABUF that can be expected when using asynchronous overlapped IO? This would obviously increase the memory utilisation of the application but I am assuming this won't be an issue for the time being because I will only ever have a couple of dozen sockets open with increased SO_SNDBUF and we are talking about threefold the original size.

Thanks for your input!

Stulle
  • 1
  • 1
  • all this not depend from - are you use synchronous or asynchronous ( "overlapped" ) I/O on socket . all I/O internal asynchronous by design. synchronous only mean that I/O manager not return control for you when driver return pending status, but wait in place, until I/O finished. no more difference. – RbMm Nov 18 '20 at 09:03
  • so i be remove "overlapped I/O" from question. simply - what is effect of `SO_SNDBUF` option. but synchronous or asynchronous I/O here does not matter – RbMm Nov 18 '20 at 09:07
  • I edit the initial question a little to hopefully make it more apparent where I was talking about async (new) or sync(old). Anyhow, what I got from the documentation is that synchronous calls will only allow you to commit SO_SNDBUF for transmission while asynchronous/overlapped allow you to commit a multiple of the buffer. So I am wondering how the system internals will handle this multiple. If they just work through the list one by one or if they try and collect multiple committed buffered packets into the send buffer. I could assume a larger buffer size would decrease memcpy in latter case. – Stulle Nov 18 '20 at 10:15
  • *how WSASend() and **overlapped non-blocking IO** actually handles the internal socket buffer.* - the *how WSASend() actually handles the internal socket buffer.* - absolute same question. `WSASend` simply pass data to kernel - I/O manager and it to driver. the driver always do asynchronous I/O. he doesn't care if you opened the file for synchronous or asynchronous I/O. and if no errors in parameters and connection active - it return `STATUS_PENDING` for send or recv requests. if you open file in asynchronous mode - I/O manager just return control for you, otherwise it wait for I/O completed – RbMm Nov 18 '20 at 12:43
  • i dont know *How reasonable is it to increase the SO_SNDBUF* . i simply try explain than answer on this question not depend from sync/async mode file open. internal handling is same – RbMm Nov 18 '20 at 12:45
  • also begin from win8 exist [RIO](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh997032(v=ws.11)) think this give much more effect (*decrease memcpy*, etc) if use [`RIO_EXTENSION_FUNCTION_TABLE`](https://learn.microsoft.com/en-us/windows/win32/api/mswsock/ns-mswsock-rio_extension_function_table) – RbMm Nov 18 '20 at 13:03

0 Answers0