Tune upload pool size and workers count

Use 1 worker only in case of small files
This commit is contained in:
Dan 2019-03-03 17:11:55 +01:00
parent 4b73358922
commit 99af3a4180

View File

@ -1447,11 +1447,13 @@ class Client(Methods, BaseClient):
file_total_parts = int(math.ceil(file_size / part_size)) file_total_parts = int(math.ceil(file_size / part_size))
is_big = file_size > 10 * 1024 * 1024 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 is_missing_part = file_id is not None
file_id = file_id or self.rnd_id() file_id = file_id or self.rnd_id()
md5_sum = md5() if not is_big and not is_missing_part else None 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)] 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(4)] workers = [asyncio.ensure_future(worker(session)) for session in pool for _ in range(workers_count)]
queue = asyncio.Queue(16) queue = asyncio.Queue(16)
try: try: