From 99af3a4180077518d1115e43bee59f92fbb48529 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 3 Mar 2019 17:11:55 +0100 Subject: [PATCH] Tune upload pool size and workers count Use 1 worker only in case of small files --- pyrogram/client/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index f58d3ceb..5181b029 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1447,11 +1447,13 @@ class Client(Methods, BaseClient): file_total_parts = int(math.ceil(file_size / part_size)) is_big = file_size > 10 * 1024 * 1024 + pool_size = 3 if is_big else 1 + workers_count = 4 if is_big else 1 is_missing_part = file_id is not None file_id = file_id or self.rnd_id() md5_sum = md5() if not is_big and not is_missing_part else None - pool = [Session(self, self.dc_id, self.auth_key, is_media=True) for _ in range(3)] - workers = [asyncio.ensure_future(worker(session)) for session in pool for _ in range(4)] + pool = [Session(self, self.dc_id, self.auth_key, is_media=True) for _ in range(pool_size)] + workers = [asyncio.ensure_future(worker(session)) for session in pool for _ in range(workers_count)] queue = asyncio.Queue(16) try: