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:
- Globally turn off Nagle algorithm (hence, affecting connections I don't want to affect).
- Increase MaxServicePointIdleTime, so that the
ServicePoint
is never recycled (probably a bad idea? My intuition tells me so). - Set some sort of timer that resets the properties every N seconds where N is smaller than the recycling time for a
ServicePoint
. - 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?