Changing TCP socket buffer sizes on macOS

HI,


We are facing speed issues while downloading on the high latency network with per-app VPN client. We are using NWTCPConnection as of now, and would like to test if changing the receive/send buffer sizes would make any difference to handle the high latency environment.


With NWTCPConnection I don't see any option to get socket FD and override the default values, is there any other way to get around this? Would we need to switch to Network Framework or NSStream instead as NSStream gives the socket FD and possible allows to change the buffer sizes.


Thanks.

Answered by DTS Engineer in 418350022

OK, I continued my chat with the Network framework team about this and the final answer is…

There’s no way to set socket buffer sizes in Network framework.

This isn’t an arbitrary restriction. As I mentioned above, Network framework is designed to live on top of the user space networking stack, and the traditional BSD Socket buffer size concept just doesn’t make sense there.

Share and Enjoy

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

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

With

NWTCPConnection
I don't see any option to get socket FD and override the default values

You are assuming that there is an underlying file descriptor, which is not always true. Depending on the system release,

NWTCPConnection
might route through to the kernel networking stack via BSD Sockets or to the user space networking stack via Network framework.

As to your overall goal,

NWTCPConnection
is a relatively lightweight API and it does not let you control low-level features like the socket buffer size. As to whether Network framework exposes these, I’m not sure. I had a quick look and couldn’t find anything obvious.

Share and Enjoy

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

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

Ok thanks Quinn, we are trying to changes the buffer sizes in "/etc/sysctl.conf" and see if it causes any improvement. Those settings would be still used by "NWTCPConnection", right?

As to whether Network framework exposes these, I’m not sure.

Wow, there it was, hiding in plain site. Check out the

availableSendBuffer
and
availableReceiveBuffer
properties on
NWProtocolTCP.Metadata
.

Share and Enjoy

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

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

Thanks Quinn. But this is read only property for inspection purpose right?

But this is read only property for inspection purpose right?

Right. Sorry about the bum steer; somehow I’ve managed to end up chasing my own tail.

I’ll dig into this again and try to follow-up here with the results.

Share and Enjoy

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

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

OK, I continued my chat with the Network framework team about this and the final answer is…

There’s no way to set socket buffer sizes in Network framework.

This isn’t an arbitrary restriction. As I mentioned above, Network framework is designed to live on top of the user space networking stack, and the traditional BSD Socket buffer size concept just doesn’t make sense there.

Share and Enjoy

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

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

Ok thanks Quinn for detailed info.

Changing TCP socket buffer sizes on macOS
 
 
Q