Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LeastActiveLoadBalance负载均衡 #904

Closed
wannshan opened this issue Nov 22, 2017 · 8 comments

Comments

Projects
None yet
3 participants
@wannshan
Copy link

commented Nov 22, 2017

74行 int offsetWeight = random.nextInt(totalWeight);//这里totalWeight是没有经过warmup降权的值的和
78 offsetWeight -= getWeight(invokers.get(leastIndex), invocation);//这个是经过warmup降权的。

当服务刚启动,经过warmup降权后的getWeight返回的值,可能经过leastCount次循环后,还是offsetWeight >0
造成选不到invoker
for (int i = 0; i < leastCount; i++) {
int leastIndex = leastIndexs[i];
offsetWeight -= getWeight(invokers.get(leastIndex), invocation);
if (offsetWeight <= 0)
return invokers.get(leastIndex);
}

@ralf0131

This comment has been minimized.

Copy link
Contributor

commented Jul 20, 2018

Hi, could you please send a pull request?

@carryxyh

This comment has been minimized.

Copy link
Member

commented Aug 1, 2018

If the offsetWeight doesn't decrease lower than 0 after loop, it maybe mean that all the least active invokers are in warmup, then the LeastActiveLoadBalance will select a random one from these same active invokers.
Or, continue to loop until the value of offsetWeight drops below 0?

How about make it like this:

int offsetWeight = random.nextInt(totalWeight);
while (offsetWeight > 0) {
    // Return a invoker based on the random value.
    for (int i = 0; i < leastCount; i++) {
        int leastIndex = leastIndexs[i];
        offsetWeight -= getWeight(invokers.get(leastIndex), invocation);
        if (offsetWeight <= 0)
            return invokers.get(leastIndex);
    }
}

But this way will cause more loops, which will make the select process more time consuming.

And or!
Declare a variable is the weight after the warmup, directly select this variable as totalWeight.
like this:

int totalWeightAfterWarmup = ...

// sth...

if (!sameWeight && totalWeightAfterWarmup > 0) {
    int offsetWeight = random.nextInt(totalWeightAfterWarmup);
    for (int i = 0; i < leastCount; i++) {
        int leastIndex = leastIndexs[i];
        offsetWeight -= getWeight(invokers.get(leastIndex), invocation);
        if (offsetWeight <= 0)
            return invokers.get(leastIndex);
    }
}
@carryxyh

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

@wannshan
Hi, the pr to solve this issue is here:

#2172

Welcome to participate in PR review :)

@wannshan

This comment has been minimized.

Copy link
Author

commented Aug 3, 2018

Change the line
int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); // Weight
TO
int weight = getWeight(invoker, invocation); // have warm up value

@carryxyh

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

@wannshan
Yeah, that is what I do.
And also, I mark the totalWeight to taotalWeightAfterWarmUp to tell coder that the weight is after warm up.

@wannshan

This comment has been minimized.

Copy link
Author

commented Aug 3, 2018

may be taotalWeightWithWarmUp will be better ,after all not after but warming....

@carryxyh

This comment has been minimized.

Copy link
Member

commented Aug 3, 2018

That make sense.
Would u pls review this into my pr? And I will fix it soon.

@carryxyh

This comment has been minimized.

Copy link
Member

commented Sep 20, 2018

Hi, I submit a new issue here:
#2540
Focus on this issue, pls.

@carryxyh carryxyh closed this Sep 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.