5

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?

Doron Yaacoby
  • 9,412
  • 8
  • 48
  • 59
  • Hmm, seems like you've listed the viable options. I would go with #4, reset properties when you create the connection. – Richard Schneider Sep 30 '15 at 05:31
  • @RichardSchneider: I would have to do that every time I use the connection, not create it. I am worried about performance and thread safety if I go this route, FindServicePoint doesn't look like the kind of method I want to call 100 times per second – Doron Yaacoby Sep 30 '15 at 05:52
  • @DoronYaacoby did you find any alternatives? I am facing the same problem and currently employ solution #4, but share your concerns regarding performance. – enzi Dec 21 '15 at 14:23
  • @enzi sadly, no. I went for solution number 1 and it didn't seem to cause performance problems with other connections, so I stayed with that. – Doron Yaacoby Dec 21 '15 at 14:33

0 Answers0