Reputation: 10618
Given three servers which A , B , C in which A can handle 50% of the traffic , B can handle 30% of the traffic and C can handle 20% of the traffic come up with a formula to distribute load efficiently. The current load of the servers is also an input to the function.
I could not come up with the "formula" he is asking for. Is there any specific answer to this question ?
Upvotes: 5
Views: 1143
Reputation: 1635
There are a few different ways to distribute load that might be applicable here.
Case 1. Random assignment biased proportionally to each servers load:
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
Case 2. Round-Robin biased proportionally to each servers load:
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
Case 3. Forget about the supposed capacity and poll for current load
let La = A, load of A
let Lb = B, load of B
let Lc = C, load of C
goto argmin (La,Lb,Lc)
Upvotes: 5
Reputation: 8586
Basically, compute a relative cost to serve on each of the servers, and over some small fixed period, sum the total cost of the requests sent to said server. Something like:
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)
Upvotes: 2