Maximize the number of simultaneous http-downloads

后端 未结 4 918
不知归路
不知归路 2020-12-16 00:35

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

相关标签:
4条回答
  • 2020-12-16 00:41

    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.

    0 讨论(0)
  • 2020-12-16 01:00

    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.

    0 讨论(0)
  • 2020-12-16 01:01

    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.

    0 讨论(0)
  • 2020-12-16 01:02

    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.

    0 讨论(0)
提交回复
热议问题