Sync Vs. Async Sockets Performance in .NET

前端 未结 3 1168
轻奢々
轻奢々 2020-12-17 17:59

Everything that I read about sockets in .NET says that the asynchronous pattern gives better performance (especially with the new SocketAsyncEventArgs which saves on the all

3条回答
  •  离开以前
    2020-12-17 18:31

    "This class was specifically designed for network server applications that require high performance."

    As I understand, you are a client here, having only a single connection.
    Data on this connection arrives in order, consumed by a single thread.

    You will probably loose performance if you instead receive small amounts on separate threads, just so that you can assemble them later in a serialized - and thus like single-threaded - manner.
    Much Ado about Nothing.


    You do not really need to speed this up, you probably cannot.

    What you can do, however is to dispatch work units to other threads after you receive them. You do not need SocketAsyncEventArgs for this. This might speed things up.

    As always, measure & measure.
    Also, just because you can, it does not mean you should.
    If the performance is enough for the foreseeable future, why complicate matters?

提交回复
热议问题