The correct way to permanently set properties on a ServicePoint

425 Views Asked by At

I would like to turn off Nagle algorithm on a specific connection (in my case - to an ElasticSearch server).

My code currently looks something like this:

ServicePointManager.FindServicePoint(new Uri(uriWithoutLocalPath)).UseNagleAlgorithm = false;

The problem is that the ServicePoint object is being recycled after a while, which causes it to lose the setting. Therefore, I can't just run this code once, at system startup. It would seem I have several options in front of me:

  1. Globally turn off Nagle algorithm (hence, affecting connections I don't want to affect).
  2. Increase MaxServicePointIdleTime, so that the ServicePoint is never recycled (probably a bad idea? My intuition tells me so).
  3. Set some sort of timer that resets the properties every N seconds where N is smaller than the recycling time for a ServicePoint.
  4. Reset the properties every time I use the connection.

I don't really like any of these options, they either affect other things in the system, or seem too complex for what I want to do (like the timer option). It seems to me that there should be a simple solution to this. Ideas?

0

There are 0 best solutions below