Adaptive worker thread count

This commit is contained in:
Leo Vasanko 2023-11-21 14:36:42 +00:00
parent 16a8011526
commit 058bc9f912

View File

@ -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)