fix(connection): 修复 SendBuffMsg 导致的 QPS 下降与延迟增加问题#408
Open
redfox1999 wants to merge 5 commits into
Open
Conversation
Author
|
@aceld 有空时看下这个PR。我第一次提PR,也不知道操作的对不 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📝 概述
本 PR 大幅优化了
connection.go中SendBuffMsg的性能。通过将原有的“固定间隔 Flush”策略改为“即时批量消费并 Flush”,同时移除了SendToQueue中在高负载下极易误判的 5ms 硬编码超时限制,最终在 10,000 并发连接测试中实现了 QPS 提升近 5 倍(从 1.2W 提升至 6.3W),同时 P99 延迟降低了约 73%。🛠️ 修改内容
connection.go(StartWriter):msgBuffChan有数据时,一次性读出通道内当前所有的积压数据进行发送,并立即执行Flush。connection.go(SendToQueue):examples/:c10k_test测试代码,用于专门模拟和压测框架在 10,000 个并发连接下的极端性能表现。📊 性能压测对比
测试场景
核心指标对比
📈 点击查看更详细的延迟分布对比
修改前延迟分布 (Before)
响应时间分布 (ms):
0- 50ms: 605 ( 0.01%)
50- 100ms: 982 ( 0.01%)
100- 150ms: 1431 ( 0.01%)
150- 200ms: 1356 ( 0.01%)
200- 250ms: 3091 ( 0.03%)
250- 300ms: 4296 ( 0.04%)
300- 350ms: 5244 ( 0.05%)
350- 400ms: 2861 ( 0.03%)
400- 450ms: 3543 ( 0.04%)
450- 500ms: 6345 ( 0.06%)
500- 550ms: 15859 ( 0.16%)
550- 600ms: 108598 ( 1.09%) █
600- 650ms: 620090 ( 6.20%) ████████
650- 700ms: 2134787 (21.36%) ████████████████████████████
700- 750ms: 3015279 (30.16%) ████████████████████████████████████████
750- 800ms: 2326172 (23.27%) ██████████████████████████████
800- 850ms: 1159192 (11.60%) ███████████████
850- 900ms: 356055 ( 3.56%) ████
900- 950ms: 124517 ( 1.25%) █
950-1000ms: 106156 ( 1.06%) █
修改后延迟分布 (Before)
响应时间分布 (ms):
0- 50ms: 1577 ( 0.02%)
50- 100ms: 6474 ( 0.06%)
100- 150ms: 6376903 (63.77%) ████████████████████████████████████████
150- 200ms: 2998511 (29.99%) ██████████████████
200- 250ms: 504442 ( 5.04%) ███
250- 300ms: 95931 ( 0.96%)
300- 350ms: 9336 ( 0.09%)
350- 400ms: 3470 ( 0.03%)
400- 450ms: 2357 ( 0.02%)
450- 500ms: 569 ( 0.01%)
500- 550ms: 310 ( 0.00%)
550- 600ms: 120 ( 0.00%)
600- 650ms: 0 ( 0.00%)
650- 700ms: 0 ( 0.00%)
700- 750ms: 0 ( 0.00%)
750- 800ms: 0 ( 0.00%)
800- 850ms: 0 ( 0.00%)
850- 900ms: 0 ( 0.00%)
900- 950ms: 0 ( 0.00%)
950-1000ms: 0 ( 0.00%)