Re: Using NSURLSession for uploading lots of prioritized files
Re: Using NSURLSession for uploading lots of prioritized files
- Subject: Re: Using NSURLSession for uploading lots of prioritized files
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Wed, 16 Jul 2014 09:50:56 +0100
On 15 Jul 2014, at 19:59, Rick Mann <email@hidden> wrote:
> I could start all my uploads at once, but we want to ensure the (small) metadata is uploaded first, even if a new one is created some time after a bunch of other large file uploads have begun.
I don't think there's a general purpose solution to this problem. NSURLSession does not have a mechanism to prioritise tasks [1].
One option is to upload the metadata files in standard session rather than a background session. If they are this small, you may be able to complete that upload in the time made available to you by a UIApplication background task. And if you run out of time, you can always cancel that upload and resume it in a background session, which leaves you no worse off than you were previously.
Another option is to use two background sessions, one for small uploads and one for large uploads. If you set HTTPMaximumConnectionsPerHost on the latter to 1, you know that it won't consume all available uploads slots (assuming all of your large uploads are going to the same host). Only uploading one file at a time shouldn't be a problem because your files are pretty big. However, you could improve that by merging the 1..100 large uploads into one single, resumable upload.
Make sure you set your large uploads to NSURLNetworkServiceTypeBackground; that'll give your small uploads priority on the wire / in the kernel. This won't help, however, if NSURLSession hasn't even started the small upload because all available slots are taken by large uploads.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
[1] Although feel free to file a bug asking for one.
<https://developer.apple.com/bug-reporting/>
Please post your bug number, just for the record.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden