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

空闲连接回收 #63

Closed
scguang301 opened this issue Oct 24, 2019 · 3 comments
Closed

空闲连接回收 #63

scguang301 opened this issue Oct 24, 2019 · 3 comments

Comments

@scguang301
Copy link

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: 7.1.3
  • Mysql version: 5.6
  • Swoole version: 4.3.3
  • SMProxy version: 1.2.9

How to Reproduce the Problem? (如何重现问题)

开始并发量比较大,达到maxConns最大连接数,然后并发量逐渐减少,但mysql连接不会减少到spareConns。

Expected Behavior (预期行为)

并发量逐渐减少,但mysql连接会减少到spareConns

Actual Behavior (实际行为)

并发量维持在最大连接数,不会减少
...

More Information (更多信息)

看代码看到只有客户端连接断开和连接池销毁时候,才根据maxSpareConns和maxSpareExp决定是否释放mysql连接, 并且$spareConns使用数组,使用时pop, 回收时相当于push,每次都使用数组尾端连接。 后面业务量减少的时候,只操作数组尾,没有达到 maxSpareExp, 不会释放。
需要定时检测每个mysql连接使用情况,超过maxSpareExp不用就释放
...

@louislivi
Copy link
Owner

mysql每过一段时间会自动断开空闲连接,目前主要是靠mysql 自动断开机制实现的回收。 之前有考虑过定时器 后面发现配合mysql 自动断开会更加高效。

@scguang301
Copy link
Author

那是服务器设置空闲连接时间,如果服务器设置8小时,这么长时间保持空闲连接,比较浪费。
定时间只是检查一下空闲连接的最后连接状态,应该不会消耗什么性能

@louislivi
Copy link
Owner

好的,谢谢你的建议 后续可以会修复这个问题。

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

No branches or pull requests

2 participants