2

Is there some way to build my own connection pool.

I'm developing an application which's connecting to a server. Each time it needs to ask for someting to server, it creates a connection and release it.

I'd like to provide a transparent way to get a connection from a pool of them.

I'm using RestSharp to build my requests:

var client = new RestClient("http://example.com");

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value");
request.AddUrlSegment("id", "123");

// easily add HTTP Headers
request.AddHeader("header", "value");

// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content;

So, perhaps the question would be aroung how to create a pool for RestSharp? Or, How to configure RestSharp for getting connections from a pool?

Jordi
  • 20,868
  • 39
  • 149
  • 333

1 Answers1

3

As you may see in RestSharp source code, RestSharp is based on well-known System.Net classes, such as HttpWebRequest and HttpWebResponse. These classes already use own pipeline.

This pipeline may be tuned if needed: Understanding System.Net Connection Management and ServicepointManager

If application continues to make requests, all pending requests would be queued on the ServicePoint and processed sequentially. If pipeline is turned on, then request is send on the connection and put in the queue of the connection. If pipelining is turned off then request would remain on the queue of the servicepoint and would be sending on the connection, as soon as free connection is available.

Related question: Is HTTP connection pooling possible?

Community
  • 1
  • 1
Ilya Chumakov
  • 23,161
  • 9
  • 86
  • 114