我读了WCF服务限制在内部排队请求,没有任何额外的代码。 是否有可能监视这些内部队列以了解,例如,填充水平?
我的目标是避免客户端可以向服务发送很多请求(例如,通过缓慢或拥塞的服务),因此如果可以监视尚未发送的传出请求数量,则客户端可能会减少流量。
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.
最满意答案
你正在寻找的是一个节流算法。 常用的这种算法是测量最近N次操作的平均延迟。 如果延迟超过一个不寻常的水平,开始节流,因为显然服务已经饱和。
你可以这样做:
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 }延迟越高,阈值越高,节流将进入更多。节流增加为二次方,因此保证收敛。
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.
更多推荐
requests,请求,service,内部,服务,电脑培训,计算机培训,IT培训"/> <meta name="des
发布评论