views:

170

answers:

2

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.

+1  A: 

The iPhone doesn't start queuing NSURConnections. That's totally your responsibility. The iPhone will start all your asynchronous NSURLConnections in parallel. The only think 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 paralel 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..

stigi
I agree, but I guess if there's not a hard limit, the answer I'm looking for is how to determine what the practical limitations are. Sure, we can arbitrarily set the limit to 2 or 3 or infinity, but I'd like to develop a more intelligent management system. I think the post I referenced in my answer comes closest to that.
DougW
A: 

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.

http://stackoverflow.com/questions/1940903/background-threads-consuming-100-cpu-on-iphone-3gs-causes-latent-main-thread

DougW