Use streaming-form-data to write the file upload to disk as it happens rather than holding it in memory and writing it at the end.
Doing this I noticed that by default nginx holds the whole request and feeds it to the app at once. This prevents proper handling and also causes a hiccup when Tornado reads the whole request in one go. Tornado doesn't even yield, causing this warning:
WARNING asyncio: Executing <Task pending name='Task-5' coro=<HTTP1ServerConnection._server_request_loop() running at /usr/local/lib/python3.8/site-packages/tornado/http1connection.py:825> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7efe01ef7fa0>()] created at /usr/local/lib/python3.8/site-packages/tornado/http1connection.py:145> cb=[IOLoop.add_future.<locals>.<lambda>() at /usr/local/lib/python3.8/site-packages/tornado/ioloop.py:688] created at /usr/local/lib/python3.8/site-packages/tornado/gen.py:867> took 4.907 seconds
Use
streaming-form-data
to write the file upload to disk as it happens rather than holding it in memory and writing it at the end.Doing this I noticed that by default nginx holds the whole request and feeds it to the app at once. This prevents proper handling and also causes a hiccup when Tornado reads the whole request in one go. Tornado doesn't even yield, causing this warning:
WARNING asyncio: Executing <Task pending name='Task-5' coro=<HTTP1ServerConnection._server_request_loop() running at /usr/local/lib/python3.8/site-packages/tornado/http1connection.py:825> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7efe01ef7fa0>()] created at /usr/local/lib/python3.8/site-packages/tornado/http1connection.py:145> cb=[IOLoop.add_future.<locals>.<lambda>() at /usr/local/lib/python3.8/site-packages/tornado/ioloop.py:688] created at /usr/local/lib/python3.8/site-packages/tornado/gen.py:867> took 4.907 seconds