How NSURLRequestNetworkServiceType behaves differently

Hi,


We are using -[NSURLSession streamTaskWithHostName:port] for our customized socket application. We would like to tune our application's performance by setting the NSURLRequestNetworkServiceType of NSURLSessionConfiguration associated with this NSURLSession.


However, based on https://developer.apple.com/documentation/foundation/nsurlrequestnetworkservicetype?language=objc, we have no idea what does each configuration mean.


For example:


1. NSURLNetworkServiceTypeCallSignaling: does this mean this is specialized for the control signal of VOIP application. What if we use this flag even if we are not signaling of a VOIP? Is this flag optimized for sending of small packet over the network or large chunk of bytes?


2. NSURLNetworkServiceTypeResponsiveData: we did a test with this flag too. Where we continous send 100 small messages every 500ms to an echo server and measures the latency till we get response from the server. Howerver, we don't see too much difference with or without this flag. So curious what this flag really mean?


Thanks,

Replies

The best explanation for these concepts is the doc comments associated with the

NET_SERVICE_TYPE_***
constants in
<sys/socket.h>
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Trying to understand this but still not very clear in sys/socket.h. One question is: if we use NSURLNetworkServiceTypeResponsiveData, does that mean NSURLSessionStreamTask will send/receive data must faster because of the underlying thread dedicated to it will have higher priority?


Thanks.

One question is: if we use

NSURLNetworkServiceTypeResponsiveData
, does that mean
NSURLSessionStreamTask
will send/receive data must faster because of the underlying thread dedicated to it will have higher priority?

No. None of this stuff is about thread priorities, because thread priorities are rarely relevant to iOS network performance (iOS devices have fast CPUs and slow networks). Rather, this is about network priorities. For example,

NET_SERVICE_TYPE_VO
says “I’m doing VoIP, and thus latency is critical but bandwidth not so much, so if there’s a place where you have to make a latency/bandwidth tradeoff, favour latency”.

To make a sensible choice here you need to be clear about what you mean by “faster”. If your goal is to move a large, fixed-size object through the network as fast as possible, you’re concerned with bandwidth, in which case network service types are rarely relevant. The default service type,

NET_SERVICE_TYPE_BE
, will typically favour bandwidth over latency. Indeed, many of the ‘high priority’ network service types will make things worse because they tend to favour latency.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"