I have a web site on Quart-Trio and Hypercorn. There is a page /search
made with Whoosh. Some search operations can take up to ~6 seconds. In production it would probably interfere with the site availability for other users.
So I think I need to run the search as a parallel task, on another processor core.
(Using Trio multitasking doesn't seem to be a good option, as the long execution is caused by data processing, not I/O operations. So I think managing tasks in one thread wouldn't help).
What is the easiest and most efficient way to do multiprocessing there?
I know there's multiprocessing
module in Python, and curio
, and hypercorn
workers, and hypercorn middleware DispatcherMiddleware
, and all that information is a bit overwhelming. DispatcherMiddleware
looks nice and easy, but would it help, or it's all in the same thread? Or maybe all I need is to start hypercorn with several workers?
Please point me in the right direction, how to solve this small task without becoming a guru in multiprocessing.
Using hypercorn with multiple workers solves the problem:
hypercorn --config conf/hypercorn.conf -k trio main:app -w 2
Two searches go in parallel.