考虑到三个服务器A,B,C,其中A可以处理50%的流量,B可以处理30%的流量,C可以处理20%的流量,得出一个公式来有效地分配负载。服务器的当前负载也是该功能的输入。
我无法想出他要求的“公式”。这个问题有什么具体的答案吗?
答案 0 :(得分:5)
分发可能适用的负载有几种不同的方法。
案例1.随机分配与每个服务器负载成比例偏差:
for each request
let x = uniformly distributed random number between 0 and 1
if x <= 0.5
goto A
else if x <= 0.8
goto B
else
goto C
案例2. Round-Robin与每个服务器负载成比例地偏向:
let x = new list
push A on x 5 times
push B on x 3 times
push C on x 2 times
for each request
y = pop x
goto y
push y to back of x
案例3.忘记当前负载的假定容量和轮询
let La = A, load of A
let Lb = B, load of B
let Lc = C, load of C
goto argmin (La,Lb,Lc)
答案 1 :(得分:2)
基本上,计算在每个服务器上提供服务的相对成本,并在一些小的固定时间段内,将发送到所述服务器的请求的总成本相加。类似的东西:
Cost_A = 20/50
Cost_B = 20/30
Cost_C = 20/20
Running_Total_A = 0
Running_Total_B = 0
Running_Total_c = 0
while true:
If One minute has passed:
Running_Total_A = 0
Running_Total_B = 0
Running_Total_c = 0
IF (Min(Running_Total_A,Running_Total_B,Running_Total_C) == Running_Total_A):
Running_Total_A += Cost_A
RouteTo(A)
ELSE IF (Min(Running_Total_A,Running_Total_B,Running_Total_C) == Running_Total_B):
Running_Total_B += Cost_B
RouteTo(B)
ELSE IF (Min(Running_Total_A,Running_Total_B,Running_Total_C) == Running_Total_C):
Running_Total_C += Cost_C
RouteTo(C)