简体   繁体   中英

How to configure DB connection pooling in Python Zope server

I'm started enhancing an application which has developed in Python. Zope server has been used to deploy the application.

In many modules DB connection has established and used for DB transaction, and which has not used any connection pooling mechanism. Considering the volume of users it is vulnerable to have DB connections established for every request and it is a bad design.

Now In order to have connection pooling, what should I do? My application uses Python 2.4,Zope 2.11.4 and MySQL 5.5.

Is Zope provides any way to achieve it, like configure the DB in external file and inside the Python code referring the connection which Zope takes care of utilizing from connection pool? Or Do I need to write in a Python code in such a way that independent of the server(Zope or other) provided MySQL module for python

I guess you've advanced with your problem, but this is not a reason not to comment.

1) Long-term answer: seriously consider building a path to migrating to ZODB instead of mysql. ZODB is integrated with Zope and is way more efficient than mysql for storing Zope data. You can't do it at once, but may be you can identify part of the data that can be migrated to ZODB first, and then do it by "clusters of data".

2) short-term answer: I don't know what library you're using to connect to mysql (there aren't many of them), let's say it's python-mysqldb, and the function to Connect to the database is Connect. You Can write your own MySqlDB module, and put it before the system MySqlDB in the sys.path (manipulating the sys.path of your zope application if necessary), so your module is called instead of the system MySqlDB one. In your module, you write a Connect function that encapsulates your pooling logic and proxy everything else to the original (system) MySqlDB module.

Hope I've been clear for you or everyone else having the same problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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