NSURLSession callbacks and GCD serial queue: latency spikes only under concurrent requests
0 reputation · 25 May 2024, 05:38 UTC
0 reputation · 25 May 2024, 05:38 UTC
I have an Objective-C networking layer where NSURLSession data-task completion handlers dispatch parsing work onto a dispatch queue. Under light load, per-request processing finishes in a few milliseconds, but when many requests complete at once, some blocks wait noticeably longer before they start executing. I am trying to decide whether the queue design or the callback integration is the bottleneck.
Parsing blocks are submitted with dispatch_async to a single serial queue so results stay ordered. I know from the GCD documentation that serial queues execute one block at a time, and that global concurrent queues are selected by QoS class via dispatch_get_global_queue. What I am unsure about is how NSURLSession's own delegate callback queue interacts with my serial queue: whether callbacks can pile up behind each other before my parsing blocks are even submitted, and whether moving parsing to a concurrent queue would actually help if the blocks also take a shared lock when writing results.
Assume a current Xcode and recent iOS/macOS target; I can verify with Instruments and os_signpost intervals.
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.