Reputation: 38401
Typically NSOperationQueue
guarantees thats that tasks with low priorities will not be executed until tasks with high priorities are done executing. However, when a large number of operations are added quickly to the queue, sometimes the operation queue can overload, as shown below
This graph tracks the history of 1000 operations. The red line shows the number of tasks with NSOperationQueueVeryLowPriority
priority that are currently executing, the green line shows the number of tasks with NSOperationQueueNormalPriority
that are idle in the queue and NOT executing, and finally the blue line shows the total number of operations in the queue.
Now, the default max concurrency of the NSOperationQueue
in this case seems to be 64. When all of those 64 slots get filled up, even if tasks with higher priorities exists, they don't get executed and have to wait. My question is, is there some way to tweak the NSOperationQueue
so that even when under load, it reserves some of the capacity for higher priority operations?
Upvotes: 3
Views: 451
Reputation: 11
I have a similar problem with NSOperation
& NSOperationQueue
.
I have a class (with NSURLConnection
) that inherits from NSOperation
. I have the NSOperationQueue
setup. I am adding approx 5000-6000 operations to that queue. The problem here is that not all the operations get executed. It stops exactly at 64. Found that the default max-thread-count during concurrent operations seem to be 64 for intel-i5 processor.
Solution is using NSRunLoop
:
Declared a NSRunLoop
that gets the currentLoop. And running the loop for a few seconds.
Doing this will exit the currentLoop every few seconds. This way, at any point in time, the max-thread-count is way less than 64. My app just works. :)
Upvotes: 1