如何使用c#实现加权循环?
如果我有一些服务器:192.168.100.1、192.168.100.2、192.168.100.3、192.168.100.4... 它们的权重是:5,1,2,3
我想实现负载均衡,但是如何使用C#实现加权循环?
If I have some servers: 192.168.100.1, 192.168.100.2, 192.168.100.3, 192.168.100.4...
and weights of them are: 5, 1, 2, 3
I want to implement load balancing, but how can I implement weighted round robin using C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您有服务器
a
、b
、c
、d
。并且您有相应的权重5
、1
、2
、3
。您可以通过以下方式进行加权循环:rand.next() % 11
返回[0, 10]
(含)范围内的均匀分布整数。我们使用服务器a
处理请求,获取五个可能的值[0, 4]
。我们使用服务器b
处理请求,仅获取一个可能的值5
,依此类推。请特别注意您使用的特定随机方法和种子值。
Say you have servers
a
,b
,c
,d
. And you have corresponding weights5
,1
,2
,3
. You can do weighted round robin in the following way:rand.next() % 11
returns a uniformly distributed integer in the range[0, 10]
(inclusive). We process the request with servera
for five of the possible values[0, 4]
. We process the request with serverb
for only one possible value5
and so on.Pay special attention to the particular random method you use and the seed value.
随机加权选择算法
加权循环算法 https://dotnetfiddle.net/71Sft0
Random Weighted Select algorithm
Weighted Round Robin Algorithm https://dotnetfiddle.net/71Sft0