round robin load_balancer优化:在第一次初始化时offset使用随机数,以适配每次都是在新线程使用的场景 #2289
+3
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number:
Problem Summary:
如果每次都是在新线程去使用rr的client,tls.offset会清空,然后重新选一个质数去取模机器数,极端情况下会出现有些机器永远都选不中的情况,server端的qps会出现明显倾斜的情况
![image](https://private-user-images.githubusercontent.com/10593758/249071286-a1c8b4a7-4017-436d-98c3-9b0b7305fead.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzOTU1MjgsIm5iZiI6MTczOTM5NTIyOCwicGF0aCI6Ii8xMDU5Mzc1OC8yNDkwNzEyODYtYTFjOGI0YTctNDAxNy00MzZkLTk4YzMtOWIwYjczMDVmZWFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDIxMjAyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZlMDg2ZmY3YjMwOTk4NWIzYzhmNzFmMTZhZGQ3N2FjNTZhNTA4MDRmMGRjMmU4YzFlMDc0NzAwYmY3MjBmOWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.OgrymnEeRarUZfRp15xWrdfFMnL3CZtQC3PsM9z9lDY)
What is changed and the side effects?
Changed:
tls.offset = butil::fast_rand_less_than(n);
在第一次使用offset时使用随机数而不是取值为0,这样可以避免第一次使用的质数的个位数只能是(1,3,7,9)这些数字的问题
Side effects:
很小
无
Check List: