Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value of maxConcurrentOperationCount for NSOperationQueue

As the title suggests, what is the default value of the maxConcurrentOperationCount for NSOperationQueue?

Is it set to a value of 1?

like image 263
lakshmen Avatar asked Feb 21 '13 06:02

lakshmen


2 Answers

From the documentation,

The maximum number of concurrent operations set explicitly on the receiver using the setMaxConcurrentOperationCount: method. If no value has been explicitly set, this method returns NSOperationQueueDefaultMaxConcurrentOperationCount by default.

So it is NSOperationQueueDefaultMaxConcurrentOperationCount. If this is set, it will choose an appropriate value based on the number of available processors and other relevant factors.

This is how it is defined:

enum {   NSOperationQueueDefaultMaxConcurrentOperationCount = -1 }; 

NSOperationQueueDefaultMaxConcurrentOperationCount: The default maximum number of operations is determined dynamically by the NSOperationQueue object based on current system conditions.

like image 156
iDev Avatar answered Sep 24 '22 07:09

iDev


In one of my apps, I add about 35k instances of NSOperation to an NSOperationQueue at once. If I set maxConcurrentOperationCount to 64, I gain about 20x of performance compared to the default value. The CPU load rises from ~120% to 400% which seems to indicate that the default value is so high that the CPU is mostly busy working on the op queue overhead.

Conclusion: if you have many short lived NSOperation it might be worth to play with the maxConcurrentOperationCount.

like image 35
Mojo66 Avatar answered Sep 23 '22 07:09

Mojo66