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

MySQL client 事务模式下内存问题 #1621

Open
yilunh opened this issue Sep 12, 2024 · 7 comments
Open

MySQL client 事务模式下内存问题 #1621

yilunh opened this issue Sep 12, 2024 · 7 comments

Comments

@yilunh
Copy link

yilunh commented Sep 12, 2024

参考教程使用事务模式的MySQL client,每次发送新事务会新建一个唯一ID的WFMySQLConnection二级工厂和seriesWork,结束后发送disconnect并回收资源。目前上线后能够正常收发请求且commit或rollback都符合预期,但经过7*24小时监控发现内存使用每天增加,而之前使用非事务模式时从未遇到过该问题。请问是我的使用姿势有误吗?

@Barenboim
Copy link
Contributor

Barenboim commented Sep 12, 2024

看起来,是你的姿势有误啊。

如果你的任务都是串行的,一直使用同一个connection就可以了,不用总是disconnect。每个ID是会占用一块资源的,并且程序退出之前不会释放。同一个ID可以用于找回之前那个连接,哪怕WFMySQLConnection对象已经释放了。

如果你无法保证事务之间不会并发,可以简单搞个ID池来解决,不用每次disconnect,相同ID相同URL,就可以复用连接。当然,也可以做成WFMySQLConnection的对象池。

@yilunh
Copy link
Author

yilunh commented Sep 12, 2024

感谢回复,请问能否完善事务使用的文档,强调一下需要管理WFMySQLConnection对象的资源,由于姿势错误造成线上内存泄漏挺严重的。

@Barenboim
Copy link
Contributor

感谢回复,请问能否完善事务使用的文档,强调一下需要管理WFMySQLConnection对象的资源,由于姿势错误造成线上内存泄漏挺严重的。

好的好的。我记得有大概提了一下。感谢使用。

@Barenboim
Copy link
Contributor

Barenboim commented Sep 12, 2024

@yilunh
Copy link
Author

yilunh commented Sep 12, 2024

感谢及时的更新。还想请问,如果复用时使用相同的ID但不同的URL初始化,是否会生成新的连接对象?对应的那一小块内存会被复用吗?

@Barenboim
Copy link
Contributor

Barenboim commented Sep 12, 2024 via email

@yilunh
Copy link
Author

yilunh commented Sep 12, 2024

感谢大佬答疑,我再研究研究

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