none
.Net Socket.SendPacketsAsync() does not fill the pipe RRS feed

  • Question

  • We recently converted one of our applications to use asynchronous socket API (SendPacketsAsync and ReceiveAsync). However we found that the application has significantly lower throughput after conversion and suffers from lots of timeout error.

    The packet capture shows that with the async API, socket does not send out a new packet until the previous packet is ACKed even though there are outgoing data in the socket's send buffer. (see screenshot below)

    The situation is improved slightly after setting "Socket.NoDelay = true", the socket now sends out two packets before stopping for ACK.

    In either case, the server's windows size is huge but the client does not try to fill that window.

    Compare with the old implementation that uses the synchronous API (Socket.Send() and Socket.Receive(): the client continues sending without receiving ACK for the prior packets.

    Does anyone know what properties on the socket can be adjusted to make it fully utilize the window size and improve the throughput of the application?


    Wednesday, December 20, 2017 4:06 PM

All replies

  • Hi Qiu, Wenning,

    Thank you for posting here.

    You could try to use Socket.ReceiveBufferSize Property or Socket.SendBufferSize Property to set a value that specifies the size of the receive or send buffer of the Socket. Consider increasing the buffer size if you are transferring large files, or you are using a high bandwidth, high latency connection (such as a satellite broadband provider.)

    Have you sent the Socket.SendTimeout Property? You could use it to send a value that specifies the amount of time after which a synchronous Send call will time out. The default value is 0, which indicates an infinite time-out period.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, December 22, 2017 6:18 AM
    Moderator
  • Thanks Wendy! 

    I think I have figured out a solution by setting "NoDelay=true". Details can be found on StackOverlow: https://stackoverflow.com/questions/47909285/net-socket-sendpacketsasync-does-not-fill-the-pipe

    A question I would like to seek answer is why SendPacketsAsync() chooses to pause for ACK when NoDelay is set to false (default) even if there are outgoing data in the socket's send buffer and the TCP window is open.


    Friday, December 22, 2017 7:05 PM
  • Hi Qiu, Wenning,

    Thanks for your sharing. Please mark the solution as answer to close the thread. This will make answer searching easier in the forum and be beneficial to community members as well.

    When you set the value of NoDelay property to false to use the Nagle algorithm. You could refer to the following link.

    https://social.msdn.microsoft.com/Forums/en-US/8c4c4f8d-1f99-47ce-a762-90645bc1e589/socketsendbuffersize-0-socketnodelay-true-multiple-calls-socketsendasync-?forum=ncl

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 25, 2017 7:48 AM
    Moderator