Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum number of concurrent NSURLConnections to the same host?

I'm running in to an issue in an OS X app that creates multiple, persistent connections to the same host using NSURLConnection. I create a separate connection for different rooms, and it stays connected the entire time the room is open to consume a streaming API. When opening many rooms, it stops working correctly.

I created a separate sample app that creates 10 connections, and it seems to only allow 6 connections to work, and the others are queued. Does anyone know if there is a way to override this limit? I can't find it documented anywhere. The only workaround I've found is it seems to be per host name, so testing with "localhost" and "127.0.0.1" allows 6 connections per host. I uploaded a sample project with client and server here - http://cl.ly/1x3K0D1F072V3U2T0C0I.

like image 467
Zach Waugh Avatar asked Jun 01 '12 16:06

Zach Waugh


Video Answer


1 Answers

I filed a Radar for something that seems like the same issue but on iOS. I found that you can't have more than 5 connections open at once. The connections don't have to be pointing to the same domain. Anything after that would be queued. So if you have 5 connections open to an extremely slow endpoint, any other connections will not go through.

Radar: http://openradar.appspot.com/radar?id=2542401

Apple's reply:

This is the effect of our NSURLConnection connection cache. It is expected. We expect to address this type of configuration with new API.

I asked if they could give me anymore information (does it vary? does the type of connection affect it?) and they said:

Unfortunately, we can't give details about the connection limit behavior.

User agents in general (Chrome, Firefox, Safari) use six simultaneous TCP connections per hostname, with potential one-offs.

like image 85
jasongregori Avatar answered Sep 23 '22 01:09

jasongregori