Good day,
I have a use case that I am currently facing problems with.
I am currently implementing a downloader service that uses some c++ code to download in the foreground, and when the user backgrounds the app, NSURLSession kicks in.
Due to chunking, we have a bunch of endpoints that contain ~1mb worth of data for each chunk, and these chunks make up a full file when processed. Small files would be downloaded as is.
As such, there might potentially be ten thousands worth of endpoints that NSURLSession might need to download from in the background.
From what I've read around here, there are four things to take note of.
Resume Rate Limiter
Number of tasks queued into nsurlsessiond
Number of concurrently running tasks
NSUrlSessionDownloadTask creation
My current implementation is to create a bunch of tasks in applicationDidEnterBackground(_:) and then starting them all at once. However, NSUrlSessionDownloadTask creation is very expensive. As a reference, it takes 3.7 seconds to create 400 tasks on my iPhone 7+.
Upwards of 500 task creation and it runs into the territory of the OS terminating my app as I did not return out of applicationDidEnterBackground(_:) in five seconds.
Creation of new tasks when the first batch ends is also not an option because of resume rate limiter. According to here, the delay is really heavy and is something I would like to avoid.
Are there any viable solutions that would solve my problem of downloading many files in the background? Thanks in advance!
6
0
2.8k