-
Notifications
You must be signed in to change notification settings - Fork 263
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 Connection Pool Doesn't Seem to Work #564
Comments
yeah, it's an issue with databases library test the working code: import aiomysql
import asyncio
async def create_pool():
pool = await aiomysql.create_pool(
host='192.168.62.195',
port=3306,
user='root',
password='xiao',
db='db_sms',
minsize=3,
maxsize=10
)
return pool
async def execute_query(pool, query):
while True:
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute(query)
result = await cur.fetchall()
# return result
print(result)
async def run_concurrent_queries(pool, num_queries):
tasks = []
query = "select * from tbl_sms_record"
async with asyncio.TaskGroup() as tg:
for tid in range(num_queries):
# tg.create_task(exec_sql(database.fetch_all, 'show tables', tid))
tg.create_task(execute_query(pool, query))
async def main():
pool = await create_pool()
num_queries = 100000
await run_concurrent_queries(pool, num_queries)
pool.close()
await pool.wait_closed()
asyncio.run(main()) TCP Connections:
and qps to 1k |
Thanks for the report! Let me know if you determine the cause — there's not a lot of activity from people that would know the reason off the top of their head. |
@Vastxiao which library works for making async database connection which supports connection pooling, raw SQL execution ? |
aiomysql comes with asynchronous connection pooling, native sql support |
@zanieb I don't know the reason for databases, but I created asmysql as a replacement. |
I am experiencing an issue with the MySQL connection pool. I have been testing the following code:
During concurrency testing, I noticed that only one TCP connection is being utilized for executing queries, while the other two initial connections remain idle.
MySQL process list output:
TCP Connections:
I expected that with 100,000 concurrent tasks, more connections would be utilized. Is this an issue with my code or the databases library?
The text was updated successfully, but these errors were encountered: