I am working on an app which uses iOS NSURLSession background session to upload the data to the S3 server. From iOS 15.x, We have observed that transfer speed has become too slow (~10 kbps).
Following is the configuration, I am using
- Create the
NSURLSessionConfigurationusing backgroundSessionConfigurationWithIdentifier - Set HTTPMaximumConnectionsPerHost to
8 - Set timeoutIntervalForRequest to
60s - Set timeoutIntervalForResource to
86400s(1 Day) - Set discretionary to
false - Set TLSMinimumSupportedProtocolVersion to
tls_protocol_version_TLSv12 - Create the
NSURLSessionusing sessionWithConfiguration - send request using uploadTaskWithRequest
When I tested with iPadOs 14.8.1, there is no degradation in performance, but with iPadOs 15.3.1 and 15.5, I can see the performance degradation (uploads getting 6x slow).
When I create the session using ephemeralSessionConfiguration upload is very fast and there is no degradation (working as before).
For all the tests, I am keeping the app in foreground only.
I have few queries:
- Is there any changes in background session configuration for iOS
15.xand greater ? - We are currently using backgroundSessionConfigurationWithIdentifier to create background sessions. Should we consider moving to background tasks introduced in iOS 13 ?
- Is it upto the OS (in this case
iOS) to schedule the requests and we (clients) has no or very little control over the transfer speeds ?
PS: The degradation is happening with iOS simulators also. In case of simulators, somehow it is dependent on macOs versions (as seen from my tests).
On macOs 12.4, in xCode 13.2, iOS 12.x, 13.x, 14.x, 15.x simulators are showing the performance degradation.
When the same app is compiled from macOs 11.4, xCode 12.4, iOS 12.x, 13.x, 14.x are not showing any performance degradation.
Any inputs would be highly appreciated.
Having struggled with this problem myself, I wanted to share the solution - for others, and also for future me when I run into this again and inevitably forget: to fix slow download speeds for uploads using a background session configuration, make sure you configure the request's network service type - this setting works for me:
.responsiveAValso worked for me. Do make sure you are only setting this if it is important that uploads happen in a timely manner - if it isn't important just hand it off to the background session with an appropriately configured timeout and let it get on with it.Note: this will only have an impact if the upload task is started while the app in the foreground. If the upload task begins when the app is already in the background (for example, you need to do some other work first with some extended background execution time and then resume the upload task) then it will ignore this and behave as if you had set it to
.backgroundwhich will be as slow as before as requests started in the background are heavily throttled.