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

round robin load_balancer优化:在第一次初始化时offset使用随机数,以适配每次都是在新线程使用的场景 #2289

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

xiaoma2015
Copy link
Contributor

What problem does this PR solve?

Issue Number:

Problem Summary:

如果每次都是在新线程去使用rr的client,tls.offset会清空,然后重新选一个质数去取模机器数,极端情况下会出现有些机器永远都选不中的情况,server端的qps会出现明显倾斜的情况
image


What is changed and the side effects?

Changed:
tls.offset = butil::fast_rand_less_than(n);
在第一次使用offset时使用随机数而不是取值为0,这样可以避免第一次使用的质数的个位数只能是(1,3,7,9)这些数字的问题

Side effects:

  • Performance effects(性能影响):
    很小
  • Breaking backward compatibility(向后兼容性):

Check List:

  • Please make sure your changes are compilable(请确保你的更改可以通过编译).
  • When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
  • Please follow Contributor Covenant Code of Conduct.(请遵循贡献者准则).

@xiaoma2015
Copy link
Contributor Author

@wwbmmm

@wwbmmm
Copy link
Contributor

wwbmmm commented Jul 10, 2023

LGTM

1 similar comment
@chenBright
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants