I am going over asyncpg\'s documentation, and I am having trouble understanding why use a connection pool instead of a single connection.
In the example given, a pool is
Elvis Pranskevichus showed two benchmarks above. I took the first one bench_asyncpg_con
and edited it, moving the con
outside the loop:
async def bench_asyncpg_con_2():
power = 2
start = time.monotonic()
con = await asyncpg.connect(**data)
for i in range(1, 1000):
await con.fetchval('select 2 ^ $1', power)
await con.close()
end = time.monotonic()
print(end - start)
And this worked much faster than bench_asyncpg_pool
I got 0.45
on this, whereas I got
1.62
on bench_asyncpg_pool
and
63.18
on bench_asyncpg_con
I'm kinda newbie in using this lib and thinking that one connection con
for a whole project would be a good choice. Correct me if I'm wrong. I will appreciate it