1

Say I have 5 NSURLSessions and I create an NSURLSessionDownloadTask under each one. I then start each task running in a for loop.

How does the threading behave for the request ? Are they executed async individually, or would they be processed serially ?

Thanks for any advice !

GuybrushThreepwood
  • 5,598
  • 9
  • 55
  • 113
  • Thanks Rob - great idea. – GuybrushThreepwood Apr 29 '16 at 16:33
  • BTW, I'd suggest using a single `NSURLSession` object for multiple downloads, as there's some overhead of having multiple session objects. It probably isn't material with only five downloads, but if the number of downloads increases dramatically, you'll see some memory impact. Also, with a single `NSURLSession`, you can specify a [`HTTPMaximumConnectionsPerHost`](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionConfiguration_class/index.html#//apple_ref/occ/instp/NSURLSessionConfiguration/HTTPMaximumConnectionsPerHost) for your `NSURLSessionConfiguration` – Rob Apr 29 '16 at 16:33
  • Thanks Rob - problem is that all the requests have different HTTP headers so need different NSURLSessionConfigurations. – GuybrushThreepwood Apr 29 '16 at 16:38
  • OK. Obviously, you can also generally specify headers at the request, too, but it doesn't sound like you have so many downloads that it's that critical. – Rob Apr 29 '16 at 18:53
  • 1
    Rob thanks - worked out how to set headers at request now - moved to one session. – GuybrushThreepwood Apr 30 '16 at 14:57

1 Answers1

0

They should be processed concurrently. You can verify this by specifying a delegate for the sessions and log the progress in downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:.

Rob
  • 415,655
  • 72
  • 787
  • 1,044