T
T
Tayrus02021-09-18 19:05:54
Python
Tayrus0, 2021-09-18 19:05:54

How to reduce the load on the processor when accessing the database?

There is a bot, it launches 10 tasks (pages are parsed) through asyncio for 1 user, in each 1 task the database is accessed 4-5 times, this loads the processor very much and the bot starts to slow down, how can I reduce the load on the processor?

UPD There are many cores on my server, but for some reason not all of them are used. I
6146f6a70d267404555913.jpeg

create a connection asyncpg.create_pool()

using

async with self.pool.acquire() as con:
            await con.execute(sql)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FOUREX, 2021-09-18
@FOUREX

Do tasks on a separate thread using the Threading library
https://docs.python.org/3/library/threading.html

K
ky0, 2021-09-18
@ky0

If the load on the database starts to slow down the rest - apparently (provided that the database is properly configured, the connection pool is enabled, requests are optimized, etc.), the time has come to distribute them to different containers / virtual machines.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question