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.
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.