简体   繁体   English

Python MySQL连接池

[英]Python MySQL connection pooling

I've looked through stackoverflow and can see some oldish posts on this and wondered what the current thinking is about pooling connections in Python for MySQL. 我浏览了stackoverflow,可以看到一些古老的文章,并且想知道当前关于在MySQL中为Python池化连接的想法。

We have a set of python processes that are threading with each thread creating a connection to MySQL. 我们有一组python进程,每个进程都在创建与MySQL的连接。 This all works fine, but we can have over 150 connections to MySQL. 一切正常,但我们可以与MySQL建立150多个连接。

When I look at the process state in MySQL I can see that most of the connections are asleep most of the time. 当我查看MySQL中的进程状态时,我可以看到大多数时间大多数连接处于睡眠状态。 The application is connecting to a Twitter streaming API so its busy but this only accounts for a few connections. 该应用程序正在连接到Twitter流API,因此它很忙,但这仅占少数连接。

Is there a good way of adding connection pooling to Python MySQL and can this be done simply without re-writing all of the existing code? 有没有将连接池添加到Python MySQL的好方法,并且可以简单地做到这一点而无需重写所有现有代码吗?

Many thanks. 非常感谢。

PT PT

See DBUtils 参见DBUtils

Maybe you have an abstract layer for MySQL, you can modify this layer to avoid rewriting all the code. 也许您有一个用于MySQL的抽象层,您可以修改此层以避免重写所有代码。

If not, you have to hack your Python-MySQL driver. 如果没有,则必须破解您的Python-MySQL驱动程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM