[TIMOB-28311] iOS: File uploads high ram usage
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | iOS |
Labels | file, httpclient, ram, upload, usage |
Reporter | Donovan Lewis |
Assignee | Abir Mukherjee |
Created | 2020-12-23T15:48:32.000+0000 |
Updated | 2021-08-28T19:15:38.000+0000 |
Description
When doing a file upload using Titanium on iOS the file will be placed into ram when the upload starts and then removed from ram when finished. This works well for a single or small file.
But when you have a large file or multiple file uploads happening at once can be an issue as it is very possible to use more than 1 GB of ram with just a few uploads of files that are not that big.
When a upload is started with a 35Mb file for example when it is placed into ram it is not 35Mb of ram usage it seems to be 2x or 3x higher. So doing multiple uploads of a file will hit the devices ram hard. This can cause the app to crash or other apps be closed by the OS that should not be closed because you choose to upload a large video or a few files.
We need the option to upload from disk not from ram. It seems we can use "NSInputStream" to upload the file from the disk not placing it into ram.
More discussed here on how to do this:
https://stackoverflow.com/questions/12626748/what-is-the-correct-way-of-sending-large-file-through-http-post-without-loading/12627138#12627138
Moved to TIMOB to investigate on this.
Here is a sample code, If you use this code with a 100 MB file to upload, one steam will use over 400 MB of ram while the upload is running. If you run multiple steams of the upload it is very easy to exhaust the devices entire amount of ram. Using a smaller file say 10MB and having multiple uploads at once it will use many hundreds or even a gigabyte of ram. This causes apps in the background to close. We need a way to not have the file being uploaded placed into ram.
Has anyone else been able to take a look at this?