Closed Vinshare closed 4 months ago
I've set max_connections to 100 and stale_timeout to 180. This means that every 180 seconds, all connections in my connection pool expire.
This stood out to me, as this would imply you're opening 100 connections at approximately the same time. That will absolutely exacerbate any kind of latency issues if your db server is slow in accepting connections.
You can try increasing the MySQL server's idle time and bumping up the stale timeout, but this sounds like the issue is in your connection management strategy. The pool implementation is fairly simple and you can write your own version that would be more tailored to your usage if you prefer going that route.
Hello,
I'm using Peewee version 3.13.3 in my project. Recently, I encountered a performance issue. While troubleshooting, I read through the code of
PooledMySQLDatabase
and found potential issues in theconnect
andclose
methods.To ensure thread safety, locking operations are performed during
connect
andclose
, and the creation and closing of database connection objects also occur within the locking process.I've set
max_connections
to 100 andstale_timeout
to 180. This means that every 180 seconds, all connections in my connection pool expire. The next attempt to connect will cyclically close these 100 connection objects. Due to the presence of locks, this process occurs in a single thread. Unfortunately, during this time, I encountered network issues, leading to delays in the entire service.Of course, this doesn't mean Peewee is bad; I'm just seeking help. Is there a better way to configure this?
Related code here: