Dawid Bugajny
07/17/2023, 9:14 AMwith KedroSession.create(...) as session:
context = session.load_context()
cat = context.catalog
return SequentialRunner().run(catalog=cat, pipeline=pipeline)[...]
I have just discovered, that my API is single-threaded and new requests have to wait untill previeous requests finish. Does anybody solution for this problem and knows how to make API multithreaded?Nok Lam Chan
07/17/2023, 9:15 AMDawid Bugajny
07/17/2023, 9:18 AMmarrrcin
07/17/2023, 9:18 AMDawid Bugajny
07/17/2023, 9:23 AMuvicorn endpoint.api:app --host 0.0.0.0 --port 80
project_path = Path.cwd()
metadata = bootstrap_project(project_path)
Nok Lam Chan
07/17/2023, 10:21 AMmarrrcin
07/17/2023, 10:58 AMkedro_pipeline_run
is not async, so there’s nothing to “await” there, check: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executorDawid Bugajny
07/17/2023, 11:10 AMAlan Tetich
07/17/2023, 11:39 AMNok Lam Chan
07/17/2023, 5:18 PMasync def
?Alan Tetich
07/17/2023, 6:13 PM@app.post("/async-endpoint")
async def test_endpoint():
loop = asyncio.get_event_loop()
with concurrent.futures.ProcessPoolExecutor(max_workers=1) as pool:
result = await loop.run_in_executor(pool, kedro_pipeline_run, *args)
https://stackoverflow.com/questions/63169865/how-to-do-multiprocessing-in-fastapi
It was also possible to remove async
from the function, but then the threads were interrupted only when kedro loaded the data, which made it faster, but not as fast as creating a new process (we have a dozen or so queries per minute, so there is no problem with creating a new process).