Answer the question
In order to leave comments, you need to log in
Why is the bot slow?
I have a bot written in python3.9, aiogram, asynchronous code everywhere, and dp.async_task scattered, that all tasks were created asynchronously, a bot on a web hook, a database on postgresql, I use asyncpg to connect, I create a pool and use connections, but when there are a lot of users, the bot starts to blunt precisely on those buttons where there is a call to the database, I sinned on the database, set logging, and it turned out that the requests themselves are completed in 100ms, and in the application (I set the timer) 1-4s, why is that ?
I also wanted to ask how it would be better
async with self.pool.acquire() as con:
async with con.transaction():
res = await con.fetch(sql, user_chat_id)
async with self.pool.acquire() as con:
res = await con.fetch(sql, user_chat_id)
async def is_person_id_blacklisted_user(self, user_id: int, place: str, person_id):
sql = 'SELECT blacklisted_id FROM blacklist_persons WHERE user_id = $1 AND place = $2 AND blacklisted_id = $3 LIMIT 1'
async with self.pool.acquire() as con:
async with con.transaction():
return await con.fetchval(sql, user_id, place, str(person_id))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question