Tert0/fastapi-discord

Sessions shouldn't be created with every request

Closed this issue · 1 comments

HKGx commented

aiohttp docs state

Note

Don’t create a session per request. Most likely you need a session per application which performs all requests altogether.

More complex cases may require a session per site, e.g. one for Github and other one for Facebook APIs. Anyway making a session for every request is a very bad idea.

A session contains a connection pool inside. Connection reusage and keep-alives (both are on by default) may speed up total performance.

We abuse that in quite a lot of places

async with aiohttp.ClientSession() as session:

async with aiohttp.ClientSession() as session:

async with aiohttp.ClientSession() as session:

async with aiohttp.ClientSession() as session:

HKGx commented

Fixed as of b903e32