From 058bc9f912afea83e974fb5f8d94307a1fb9e359 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Tue, 21 Nov 2023 14:36:42 +0000 Subject: [PATCH] Adaptive worker thread count --- cista/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cista/app.py b/cista/app.py index 6c879b5..49e33cf 100644 --- a/cista/app.py +++ b/cista/app.py @@ -3,6 +3,7 @@ import datetime import mimetypes import threading from concurrent.futures import ThreadPoolExecutor +from multiprocessing import cpu_count from pathlib import Path, PurePath, PurePosixPath from stat import S_IFDIR, S_IFREG from urllib.parse import unquote @@ -33,8 +34,9 @@ app.exception(Exception)(handle_sanic_exception) @app.before_server_start async def main_start(app, loop): config.load_config() + N = max(2, min(8, cpu_count())) app.ctx.threadexec = ThreadPoolExecutor( - max_workers=3, thread_name_prefix="cista-ioworker" + max_workers=N, thread_name_prefix="cista-ioworker" ) await watching.start(app, loop)