Skip to content

Socket Pool #26287

Closed
Closed

Description

@felipepessoto

There is several performance critical scenarios that can benefit from Socket reuse through pooling.

Have you considered it?

I'm not sure about the API, if it would be a new class (with Rent and Return), or a implementation in Socket itself (like SqlConnection).

Here we have a sample, but based on TcpClient: https://www.codeproject.com/Articles/35011/NET-TCP-Connection-Pooling. It is very simple and uses lock.

Activity

  1. svick commented on May 26, 2018

    @svick
    Member

    Do I understand it correctly that this applies to scenarios where all of the following apply?

    • You're not using HTTP.
    • You need to send/receive multiple messages to the same server.
    • Using a single socket is not enough.
  2. felipepessoto commented on May 26, 2018

    @felipepessoto
    ContributorAuthor

    Exactly

  3. karelz commented on May 27, 2018

    @karelz
    Member

    I wonder if such kind of pooling would be better to be done on top of Sockets - similar way SocketsHttpClient does it.

  4. AnthonySteele commented on Jul 16, 2018

    @AnthonySteele

    Are the Socket methods Send or SendTo thread-safe, i.e. can be used in a re-entrant manner similar to HttpClient.SendAsync and co, in order to "to send multiple messages to the same server" ?

    Our use is for StatsD, sending data over Ip or Udp.

    If yes it is thread-safe, then the docs don't mention that, and they should.
    If not, then we could also use a fast thread-safe socket pool instead.

    edit : No, sockets don't seem to be thread-safe.

  5. sgf commented on Jul 12, 2019

    @sgf

    im used TCP and tested the Socket.Disconnect(true); API on windows its very stupid.
    its will blocked call and take about 2 mins;
    and im tried modify the Regedit path HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
    Added TcpTimedWaitDelay and set to 30,no effect.
    For Language competitive, performance is so important.
    how socket performance will better at .net core 3.0 or 5.0

  6. sgf commented on Jul 12, 2019

    @sgf

    I found some of my concerns and issues you mention are not the same.
    your's is reuse the connection.
    my's is reuse the socket object(include handle and kernel's resources)

  7. stephentoub commented on Jul 13, 2019

    @stephentoub
    Member

    tested the Socket.Disconnect(true); API on windows its very stupid.
    its will blocked call and take about 2 mins;

    @sgf, I'm not clear on what your comments have to do with this issue. If you're facing what you believe is a performance issue with Disconnect, please open a new issue specific to that, including a repro we can run to see the behavior you discuss. Thanks.

  8. sgf commented on Jul 13, 2019

    @sgf

    tested the Socket.Disconnect(true); API on windows its very stupid.
    its will blocked call and take about 2 mins;

    @sgf, I'm not clear on what your comments have to do with this issue. If you're facing what you believe is a performance issue with Disconnect, please open a new issue specific to that, including a repro we can run to see the behavior you discuss. Thanks.

    i will do that,open new issue for the Disconnect.

  9. karelz commented on Sep 9, 2019

    @karelz
    Member

    Triage: We do not think we need this type of API without clear customer demand and benefit. It can be built on top of our APIs if needed. If it proves to be super-popular, we can always reconsider adopting it into the platform.

  10. transferred this issue fromdotnet/corefxon Jan 31, 2020
  11. added this to the 5.0 milestone on Jan 31, 2020
  12. ghost locked as resolved and limited conversation to collaborators on Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionarea-System.Net.Sockets

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions