Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is HTTP connection pooling possible?

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?

like image 950
nl-x Avatar asked Feb 26 '13 09:02

nl-x


People also ask

What is HTTP connection pooling?

When you set up connection pooling, instead of closing the client HTTP connection after use, CICS keeps the connection open and stores it in a pool in a dormant state. The dormant connection can be reused by the same application or by another application that connects to the same host and port.

When should you not use connection pooling?

You reuse a prior database connection, in a new context to avoid the cost of setting up a new database connection for each request. The primary reason to avoid using database connections is that you're application's approach to solving problems isn't structured to accommodate a database connection pool.

How do I monitor HTTP connection pool?

Go to Monitoring and Tuning > Performance Viewer > Current activity , select server, then in PMI viewer select Settings > Log to define logging period and format. And in Modules > Thread pools > WebContainer you can view current counter values. This is rather for short term monitoring, than for constant logging.

Is connection pooling necessary?

Using connection pools helps to both alleviate connection management overhead and decrease development tasks for data access. Each time an application attempts to access a backend store (such as a database), it requires resources to create, maintain, and release a connection to that datastore.


1 Answers

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.

like image 58
spender Avatar answered Oct 11 '22 01:10

spender