4

I read that WCF service throttling enqueues requests internally without any additional code. Is it possible to monitor these internal queues to know, for example, the filling level of?

My goal is to avoid that a client can send many requests to a service (for example, via a slow or congested service), so if it were possible to monitor the amount of outgoing requests not yet been sent, the client might less traffic.

enzom83
  • 8,080
  • 10
  • 68
  • 114
  • 1
    It doesn't look like this is possible - http://social.msdn.microsoft.com/Forums/en/wcf/thread/e5335f94-bf9a-4f88-8d19-0cc8b09fab2c – Eamonn McEvoy Jun 28 '12 at 13:37
  • I just read the link you provided... Thanks! However I have added some detail to the question in order to explain my goal. – enzom83 Jun 28 '12 at 13:47

1 Answers1

1

What you are looking for is a throttling algorithm. A common such algorithm is to measure average latency over the last N operations. If latency rises above an unusual level, start to throttle, because apparently the service is saturated.

You can do it like this:

while (true) {
 var avgLatencyInSec = GetLatencyAverage();
 var thresholdLatency = 0.1; //100ms default latency
 var latencyDiff = Math.Max(0, avgLatencyInSec - thresholdLatency);
 Thread.Sleep((latencyDiff / thresholdLatency) * (latencyDiff / thresholdLatency));
 //you need to tune the sleep amount by a constant factor
}

The more your latency is above threshold the more throttling will kick in. Throttling rises quadratically so it is guaranteed to converge.

usr
  • 168,620
  • 35
  • 240
  • 369
  • In order to calculate this factor, should I perform some tests by trying different values​​ (then choose the factor which seems to be a sufficient time interval to limit the sending of requests)? – enzom83 Jun 28 '12 at 14:10
  • Yes, try it. This algorithm needs just a little tuning. The quadratic increase in throttling makes sure that you don't need to get it perfectly right. It will self-tune to a degree. – usr Jun 28 '12 at 14:12