UploadFile hogs RAM
See original GitHub issueGood day,
We are using FastAPI to access large (1GB) files through starlette UploadFile and we have noticed that all the file is loaded into RAM.
Looking at the code I see that starlette uses SpooledTemporaryFile, however it initializes it [1] with default parameters, namely max_size=0
. The thing is that SpooledTemporaryFile.write() methods calls self._check()
to switch to disk IO, however with max_size=0
it never does it [2] and hence the whole file is loaded to RAM.
I suggest to starlette’s UploadFile to:
- Set positive
max_size
by default - Accept user-defined value from constructor
What do you think?
[2] https://github.com/python/cpython/blob/master/Lib/tempfile.py#L650
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
java - High memory usage when uploading a multipart file to ...
When testing the method with a 25MB file, the memory usage of my Java Spring application in a Kubernetes cluster setup spiked up...
Read more >RAM being maxed out while uploading huge file
My issue is each time I try to upload the 14.4GB video to YouTube on chrome, opera, firefox. The web-browser crashes.
Read more >Dropbox using high amount of RAM / memory
I'm really surprised that Dropbox often appears at the top five or four culprits. It takes up over 400 MB, which is insane...
Read more >Bug #3089: Slow upload / Increase CPU/Memory usage with ...
Our uploads are ~200MB binary files which are handed to a cgi program. The upload took around 1-2min before and after the upload...
Read more >Home just destroying RAM while using custom import...
Normally when I am in an empty home it uses around 30% of my RAM, which is fine ... But you could upload...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, so 1MB would be a good midway point between that and Django’s default.
Yup for sure - it’s just exercising a standard bit of Python stdlib, so not an issue at all.
PR ready.