编写加权负载均衡算法 [英] Writing a weighted load balancing algorithm

查看:80
本文介绍了编写加权负载均衡算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个加权负载平衡算法,并且正在寻找一些参考.有书吗?您可以建议您了解此类算法.

I've to write a weighted load balancing algorithm and I'm looking for some references. Is there any book ? that you can suggest to understand such algorithms.

谢谢!

推荐答案

这里的简单算法并不复杂.

A simple algorithm here isn't that complicated.

假设您具有以下权重的服务器列表:

Let's say you have a list of servers with the following weights:

A 10
B 20
C 30

较高的权重表示可以处理更多的流量.

Where the higher weight represents it can handle more traffic.

只需将发送到每个服务器的流量除以权重,然后从最小到最大排序即可.排在最前面的服务器可以吸引用户.

Just divide the amount of traffic sent to each server by the weight and sort smallest to largest. The server that comes out on top gets the user.

例如,假设每台服务器从10个用户开始,那么顺序将是:

for example, let's say each server starts at 10 users, then the order is going to be:

C - 10 / 30 = 0.33
B - 10 / 20 = 0.50
A - 10 / 10 = 1.00

这意味着接下来的5个请求将发送到服务器C.第6个请求将发送到C或B.第7个请求将发送到未处理第6个请求的任何一个.

Which means the next 5 requests will go to server C. The 6th request will go to either C or B. The 7th will go to whichever one didn't handle the 6th.

要使事情复杂化,您可能希望平衡器更加智能.在这种情况下,它需要跟踪每个服务器当前正在处理多少个请求,并在完全满足该请求时减少它们.

To complicate things, you might want the balancer to be more intelligent. In which case it needs to keep track of how many requests are currently being serviced by each of the servers and decrement them when the request is completely fulfilled.

进一步的并发症包括增加会话的粘性.这意味着平衡器必须检查每个请求的会话ID,并跟踪它们上次到达的位置.

Further complications include adding stickiness to sessions. Which means the balancer has to inspect each request for the session id and keep track of where they went last time.

总的来说,如果您可以从已经做到这一点的公司购买产品.

On the whole, if you can just buy a product from a company that already does this.

这篇关于编写加权负载均衡算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆