How and where the TCP connection has been created in httpwebrequest, and how is it related to servicepoint?

后端 未结 1 1733
感动是毒
感动是毒 2020-12-21 14:59

I am trying to find out when the TCP connection has been established while using HttpWebRequest, how these connections have been pooled and reused using ServicePoint.

<
相关标签:
1条回答
  • 2020-12-21 15:20

    K, after browsing through code some time I think I kind of understood the abstractions. Basically servicepoint, servicepoint manager, how the tcp connection has been created, connections have been pooled, queued etc. always confused me. Below information kind of helped me - hopefully this is useful for others who are curious or tried to understand these details:

    ServicePoint: High level abstraction of 'connection' to a particular host (destination Host Ip:port) (that's why for ex, function static ServicePoint FindServicePoint(string host, int port) is defined in servicePointManger.

    ServicePointManager: as the name indicates its the global (static) class which manages service points.

    Connection (internal class): Basically this is the one I think that represents TCP connection. it basically derives from System.Net.PoolStream (internal class - it has the definitions of the sockets its using) which derives from stream.

    ConnectionGroup (internal class): Each HttpWebRequest is associated with a connection group. (basically based on connectionLimit it creates at most connectionLimit (can be configured globally through ServicePointManager, and also per httpwebrequest using its servicePoint property) number of connection objects per httpwebrequest)

    If the connection limit is reached, its simply queued and passed to the wire (most likely - but still didn't get the code which does this).

    And if you are connecting to service on the local machine, the servicepoint.connectionlimit no longer equal to servicepointmanager.defaultconnectionlimit. it defaults to; int.Maxvalue (2147483647 or 7FFFFFFF) ( you may refer to: http://blogs.microsoft.co.il/idof/2011/06/20/servicepointmanagerdefaultconnectionlimit-2-depends/ )

    Update:

    Looks like following two links are useful too:

    System.Net.ServicePointManager.DefaultConnectionLimit and .MaxServicePointIdleTime

    http://blogs.msdn.com/b/jpsanders/archive/2009/05/20/understanding-maxservicepointidletime-and-defaultconnectionlimit.aspx

    Best Regards!

    0 讨论(0)
提交回复
热议问题