Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many simultaneous (concurrent) network connections does iphone support?

I can't seem to find this anywhere, but I'm sure there must be an answer...

How many simultaneous HTTP connections can an iphone app service? In other words, if I build and run a bunch of NSURLConnections asynchronously, how many can be in flight before it starts queuing them?

Also, is there a method to check how many threads are available and/or in use programmatically?

I'm trying to write an intelligent pre-fetching engine, and these limits (if any) would be useful information.

like image 945
DougW Avatar asked May 20 '10 20:05

DougW


2 Answers

So the reason I assumed there may be a simultaneous connection limit at the mobile OS level is because many mobile browsers enforce one. There are techniques for speeding up loading speed of the mobile version of your website by ensuring that there are as few additional content fetches as possible. Images are the main culprit, but css files, javascript files, etc all require an additional connection.

In mobile, setting up and tearing down a connection is much more expensive than a single connection with more data, and one technique for improving page load performance is embedding your CSS and javascript in the page itself.

It sounds like this limitation may not exist in the OS itself, at least on the iphone platform.

As far as an answer to this question, I found this post that discusses the practical limitations of simultaneous connections. It's not a hard limit, but I think it answers the point of the question.

Background threads consuming 100% CPU on iPhone 3GS causes latent main thread

like image 40
DougW Avatar answered Nov 20 '22 06:11

DougW


The iPhone doesn't start queuing NSURConnections. That's totally your responsibility. The iPhone will start all your asynchronous NSURLConnections in parallel. The only thing that will stop it is your memory :) I recently implemented a connection pool (my solution was based on NSOperationQueue) just because of that. Now I can control parallel connections and my app doesn't crash when loading hundreds of avatar images.

About your second question. I actually don't know about a way to get the list of current threads. I had a look at NSThread API but no sign of an API for that..

like image 160
stigi Avatar answered Nov 20 '22 05:11

stigi