Hotfix/add connection pool for postgresql only #176
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add connection pool and make it work correctly.
Description
So basically, I am using Tortoise in my Project which needs to handle more than 20000 QPS, thus the asyncpg connection pool is required. So I've tried to incorporate PR 141's asyncpg/client and base/client into tortoise, so at lease I can get a temporary connection pool version of tortoise to get my project work. But after a little pressure test, (somewhere around 120 requests/s, 3 create per transaction, 40 transactions/s), error occurs, says a "transaction is already closed", which means the ddl s inside the same transaction were using different connections. it's because the execute_insert function inside AsyncpgDBClient is creating new connections wether it's inside a transaction or not, so in order to let all ddl s use same connection, I use a contextvars to store the transactionwrapper instance in the current coroutine context.