Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

For a C# webservice that contacts a limited set of other servers, I wish to create 1 HTTP connection pool per server that I want to be able to contact.

The basic concept of course:

  • Each pool should open a few connections (3 connections?) to its remote webserver, and keep those connections alive.
  • A max-time-to-life should be used to recycle (disconnect/reconnect) the connections to the remote webserver, preventing the remote web server to disconnect before we do.
  • The connections should not be created simultaneously but with a little pause between the 3 connections so the recycling also does not happen simultaneously.
  • If the remote webserver still does disconnect unexpectedly, it should be noticed and we should reconnect.
  • If reconnecting is not possible for some reason, a retry should be done after a little pause.

This way, when I want to send a HttpWebRequest, I have ready-to-use connections, sparing the time of setting up the connection at the moment that I want to use it.

At the moment I don't know if this is even a default feature of HttpWebRequest. So sorry if I'm asking for the obvious. Googling for this only led me to similar questions for Java.

Question 1: is there such a thing present in .NET/c#?

Question 2: if not, is there a resource on this present on the internet, that you know of?

Question 3: if not, how to approach building one myself?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
280 views
Welcome To Ask or Share your Answers For Others

1 Answer

HttpWebRequest (which essentially means all Http APIs in .net) already makes use of connection pooling by default.

Take a look at ServicePoint and ServicePointManager classes if you need to manage any of the parameters of the connection pool.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...