Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 multipart upload too slow in background - iOS

I am using AWS S3TransferUtility's uploadUsingMultipart(fileURL, bucket, ...) function in my iOS app to upload video files to an S3 bucket. The uploads happen very fast whenever the app is in foreground. But as soon as the app goes in the background, the upload process is very slow and is taking too much time to complete.

For example, I tested using a 100 MB file on an internet connection with upload speed 10 Mbps and it took 35 seconds to upload using multipart when the app was in the foreground but it took 14 minutes 40 seconds to upload the same file using multipart when the app was in the background.

Is there a way to speed up the upload process in the background ?

like image 591
Rishabh Sinha Avatar asked Jan 29 '19 07:01

Rishabh Sinha


1 Answers

Since the answer is long, am updating as a answer.

As per the Apple’s documentation on Background Execution, it says:

Suppose if you are running a process and in between you press the home button and your app goes to the background, then your app should get some time to finish what it was doing or at least in most cases it should be able to save any important data. This is where you are requesting the os for the background execution.

Normally the OS will give upto 3 minutes(180 seconds) to complete the task . This is just a general observation. The time can be greater than or less than 3 minutes.This is not given in the official documentation.

If you don’t call endBackgroundTask() after a period of time in the background, your app will be terminated. you will end up in losing the upload.

Idea:

  1. If your task not being finished in the allocated time (3 minutes), you can post some local notification to the user states "open you application to resume the upload"
  2. you can upload by batches (dropbox uses chunkers to upload or update the data)
  3. if you take a look at whatsapp, google photos. it will alert you when you going to background while uploading.
  4. Before uploading, check if the data is huge then alert user. if the accept it the upload it.
  5. Have option to upload only on wifi

WARNINIG: There is no way of doing the infinite or long running task in the background

like image 164
karthik Avatar answered Oct 19 '22 21:10

karthik