Re: Techniques for limiting concurrent downloads via NSURLSession
Re: Techniques for limiting concurrent downloads via NSURLSession
- Subject: Re: Techniques for limiting concurrent downloads via NSURLSession
- From: Jens Alfke <email@hidden>
- Date: Wed, 29 Jul 2015 16:55:37 -0700
> On Jul 29, 2015, at 4:46 PM, Rick Mann <email@hidden> wrote:
>
> In my application I have to download hundreds to maybe a thousand files for each "thing" that gets downloaded. I tried just kicking off a bunch of download tasks in a loop, but eventually I either get "Too many open files" errors, or I crash (this is on an iPad).
I’m not experienced with NSURLSession, but NSURLConnection limits the number of open sockets (to about 4 on iOS, maybe 8 on Mac OS). If you issue more simultaneous requests than that, they queue up waiting for an available socket.
I would think that NSURLSession has the same behavior. Are you perhaps creating a separate NSURLSession for each download? I suspect that the sockets are managed by each instance of NSURLSession, not globally as with NSURLConnection, so if you create a ton of NSURLSessions you’re consuming unlimited sockets. If so, the solution would be to create only one NSURLSession and issue all your requests through it.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden