Maximize the number of simultaneous http-downloads
Asked Answered
U

4

12

I'am trying to perform as many as possible simultaneous http-downloads an IPad2 ( ios6.0 ). This is pure for testing what is possible on this device. Even not interested in GUI performance ( not important if it doesn't respond )

I've created a special HTTP-server that sends for x minutes data to the client. The data received is of no importance. I just measure the speed an how many concurrent downloads. I've implemented 2 different ways of scheduling 12 HTTP-requests.

NSOperation

One is done by using NSOperation objects in a Queue and set the NSOperationQueueDefaultMaxConcurrentOperationCount on 12

NSThread

The second implementation is by creating 12 NSThreads that perform a synchro http-request.

The requests are all sent to the same destination IP.

Observation

What I observe is that in both cases the 6th to 12th request get a TimeOut ( errorcode -1001 ). If 1 put the timeout-value to 80.0 seconds, I see that the 6th download starts when the 1st is done.

Questions

  • Is there in IOS a limit on how many concurrent downloads?
  • Is there an other way to perform these concurrent downloads ?
  • Is there a way to bind a thread to a core ( so that it doesn't get an interrupt, like cpuaffinity in C++ ) or thread priority
Ultrasonics answered 26/2, 2013 at 12:38 Comment(0)
M
20

You can have maximum of 5 simultaneous connections to the same server. It's an iOS fixed limit and it's probably because of some http protocol constraints. You can read a bit more info here.

Methanol answered 26/2, 2013 at 12:41 Comment(6)
This is indeed what I observe at the moment. So I'm not the only one to notice this. So I can assume my implementation wasn't wrong...Ultrasonics
Yes, although the scenario with the 12 NSThreads is a bit more expensive than the first one...Methanol
is there an apple link which specifies that ?Knelt
This has been reduced to 4 concurrent connections as of iOS 7. There is no Apple link that I know off, but here is some code you can use to test the limit.Doggery
If it is indeed a per server limit, you could theoretically circumvent this limit by using a wildcard subdomain DNS configuration and generating random subdomains for each request. Obviously this is only possible if you have the ability to set this up on the server side.Pickwickian
I'm not sure this answer is still correct. The maximum of 4 simultaneous connections that are allowed are per NSURL session: developer.apple.com/documentation/foundation/…. The app is allowed to make more requests at the same time using different sessions.Mel
P
4

Just a bump to this in case anyone is still looking. I see it to be 4 simultaneous on my iPhone6S+. Here were my test steps:

  • I wrote a PHP script that does sleep(10) before echoing something back.
  • I added a button (so I can execute well after startup)
  • Hitting that button triggers 30 simultaneous NSURLConnections (synchronous requests, but each in a separate thread), and an NSLog.
  • The completion for each does an NSLog

The results are like clockwork. The first responses (4 of them) come back 12 seconds after the request (presumably 2 seconds to turn the radio on or whatever), but then each subsequent block of 4 responses come 10 seconds after the prior block of 4. All 4 at a time.

Hope that helps someone.

Poetics answered 27/7, 2016 at 21:56 Comment(0)
J
3

After looking into this for a project I found something in Apple's documentation for NSURLSessionConfiguration.

From Apple's documentation --

This property determines the maximum number of simultaneous connections made to each host by tasks within sessions based on this configuration.

This limit is per session, so if you use multiple sessions, your app as a whole may exceed this limit. Additionally, depending on your connection to the Internet, a session may use a lower limit than the one you specify.

The default value is 6 in OS X, or 4 in iOS.

Jessjessa answered 19/8, 2016 at 21:2 Comment(0)
T
1

Is there in IOS a limit on how many concurrent downloads?

This is, by the way, a per server-based limit, not an iOS limit. If you try doing this from different servers at the same time, you will see that you can exceed your current limit.

Is there an other way to perform these concurrent downloads?

Obviously you could do something with GCD, too, manually managing concurrent requests, but I think NSOperationQueue is an excellent solution and see no reason to look further than that. I certainly don't see any advantages to using threads, either.

You should benchmark the total elapsed time as the number of concurrent requests increases, but I'm sure you'll hit a point of diminishing returns. Just having more concurrent requests does not ensure better total performance.

Tonneson answered 26/2, 2013 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.