Peter Lapisu Peter Lapisu - 25 days ago 16
iOS Question

How does the maxConcurrentOperationCount of the NSURLSession delegateQueue effects task concurency

I'am using AFNetworking 3.0 which uses

and also an operationQueue (property of the
), which is used as the delegateQueue for the

so simply put


AFNetworking 3 code

self.operationQueue = [[NSOperationQueue alloc] init];
self.operationQueue.maxConcurrentOperationCount = 1;
self.session = [NSURLSession sessionWithConfiguration:self.sessionConfiguration delegate:self delegateQueue:self.operationQueue];

from the Apple docs. to NSURLSession delegateQueue

An operation queue for scheduling the delegate calls and completion handlers. The queue need not be a serial queue. If nil, the session creates a serial operation queue for performing all delegate method calls and completion handler calls.

does setting the
self.operationQueue.maxConcurrentOperationCount = 4;
means that there will be max. 4 simultaneously handled
? and setting it to = 1 (default of AFNetworking) means there is only one task at the time, and it must finish for the other one to begin?

Or i'am i wrong and this only affects the delegate message delivery, meaning that setting it to 4 can trigger a delegate callback on 4 different threads... and setting to 1 means that the callback is always on the same thread, but the tasks are handled concurrently anyway


That queue is the delegate queue, so it should only affect delegate message delivery.

When you create an NSURLSession you give it a configuration object of type NSURLSessionConfiguration.

NSURLSessionConfiguration includes a property HTTPMaximumConnectionsPerHost that lets you control the number of simultaneous connections to a single host. That's the only mechanism I'm aware of that lets you control the number of connections.