perf(net/gclient): optimize default http.Transport connection pool configuration#4390
Merged
Conversation
Contributor
Author
Contributor
Author
// http.Transport 的默认连接池参数
transport := &http.Transport{
MaxIdleConns: 100, // 最大空闲连接数
MaxIdleConnsPerHost: 2, // 每个host的最大空闲连接数(问题关键!)
MaxConnsPerHost: 0, // 每个host的最大连接数(0表示无限制)
IdleConnTimeout: 90 * time.Second, // 空闲连接超时时间
ResponseHeaderTimeout: 0, // 响应头超时
ExpectContinueTimeout: 1 * time.Second,
}问题一:MaxIdleConnsPerHost: 2 限制过严这是最严重的问题: // 默认每个host只能保持2个空闲连接
// 对于高并发场景,这会导致大量的连接重建开销影响:
问题二:MaxConnsPerHost: 0 无限制// 没有限制每个host的最大连接数
// 可能导致连接数爆炸,耗尽文件描述符风险:
问题三:超时设置不合理// 缺少必要的超时控制
ResponseHeaderTimeout: 0, // 无响应头超时
TLSHandshakeTimeout: 0, // 无TLS握手超时 |
houseme
approved these changes
Aug 28, 2025
hailaz
approved these changes
Aug 28, 2025
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.
Please ensure you adhere to every item in this list.
<type>[optional scope]: <description>For example,fix(os/gtime): fix time zone issue<type>is mandatory and can be one offix,feat,build,ci,docs,style,refactor,perf,test,chorefix: Used when a bug has been fixed.feat: Used when a new feature has been added.build: Used for modifications to the project build system, such as changes to dependencies, external interfaces, or upgrading Node version.ci: Used for modifications to continuous integration processes, such as changes to Travis, Jenkins workflow configurations.docs: Used for modifications to documentation, such as changes to README files, API documentation, etc.style: Used for changes to code style, such as adjustments to indentation, spaces, blank lines, etc.refactor: Used for code refactoring, such as changes to code structure, variable names, function names, without altering functionality.perf: Used for performance optimization, such as improving code performance, reducing memory usage, etc.test: Used for modifications to test cases, such as adding, deleting, or modifying test cases for code.chore: Used for modifications to non-business-related code, such as changes to build processes or tool configurations.<type>, specify the affected package name or scope in parentheses, for example,(os/gtime).Fixes #1234orUpdates #1234(the latter if this is not a complete fix) to this comment
提交前请遵守每个事项,感谢!
<类型>[可选 范围]: <描述>例如fix(os/gtime): fix time zone issue<类型>是必须的,可以是fix、feat、build、ci、docs、style、refactor、perf、test、chore中的一个<类型>后在括号中填写受影响的包名或范围,例如(os/gtime)Fixes #1234,如果不是完全修复则添加Updates #1234