2
我將通過asyncpg
的文檔,並且我無法理解爲什麼使用連接池而不是單個連接。asyncpg - 連接vs連接池
在example given,一個池用於:
async with pool.acquire() as connection:
async with connection.transaction():
result = await connection.fetchval('select 2^$1', power)
return web.Response(
text="2^{} is {}".format(power, result))
,但它也可以做到通過創建必要時的連接:
connection = await asyncpg.connect(user='postgres')
async with connection.transaction():
result = await connection.fetchval('select 2^$1', power)
return web.Response(
text="2^{} is {}".format(power, result))
什麼用池在必要的連接優勢?