WCF内部队列监视(为了避免向服务发送太多的请求)(WCF internal queues monitoring (in order to avoid sending too many request

编程入门 行业动态 更新时间:2024-10-27 15:27:15
WCF内部队列监视(为了避免向服务发送太多的请求)(WCF internal queues monitoring (in order to avoid sending too many requests to the service))

我读了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

本文发布于:2023-07-09 00:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082121.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:太多   队列   为了避免   queues   internal

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!