My monitor was cutting my download speed by 75%
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
My monitor was cutting my download speed by 75%
Somehow I am one of those few very lucky people to have the opportunity of owning a 2.5 gig symmetrical line for my internet. But one day, when I wanted to brag to my equally nerdy friends, shock and horror: 600 Mbps down? Luckily my upload speed was still 2.4 Gbps, so I didn’t lose all my bragging rights, but that’s weird, right? If anything, you’d expect the opposite!
不知何故,我是极少数幸运儿之一,有机会拥有一条 2.5 Gbps 对称的互联网线路。但有一天,当我想向同样书呆子气的朋友炫耀时,却感到震惊和恐惧:下载速度只有 600 Mbps?幸运的是,我的上传速度仍然是 2.4 Gbps,所以我并没有失去所有的炫耀资本,但这很奇怪,对吧?如果非要说的话,你反而会预料到相反的情况!
My ISP is pretty cool. It’s run by this one guy (Hey Keith!), and I know I can always message them and they respond promptly, as they did this time. We tried to run through a few debugging steps, they checked on their end, and everything was normal. I tried my work laptop too, same speed.
我的互联网服务提供商(ISP)很棒。它由一个人运营(嘿,Keith!),我知道我随时可以给他们发消息,而且他们会及时回复,就像这次一样。我们尝试进行了一些调试步骤,他们在终端进行了检查,一切正常。我也试了我的工作笔记本电脑,速度也是一样的。
I didn’t have time for debugging, because I needed to travel 2000 km to the other side of the continent for a family emergency.
我没有时间进行调试,因为我需要为了处理家庭紧急情况,前往 2000 公里外的大陆另一端。
But as soon as I got back, I got curious again. What could it be? In retrospect, I now know when it started: when I moved all my connections onto my Studio Display XDR. I wanted to have a one-cable setup, and the monitor offered me that. I’ve had it for half a year now, and I don’t think I’ve ever run a speed test through it. 600 Mbps was more than fast enough for me to never realise I wasn’t getting three quarters of the speed I was paying for 🤦
但当我回来后,我再次感到好奇。这到底是怎么回事?回想起来,我现在知道问题是从什么时候开始的:当我把所有的连接都转移到我的 Studio Display XDR 上时。我想要一个单线连接的设置,而显示器正好提供了这一点。我已经用了半年了,我想我从来没有通过它运行过速度测试。600 Mbps 对我来说已经足够快了,以至于我从未意识到我没有获得我所支付的三分之四的速度 🤦。
Pings to other wired computers during a download would fail 10% of the time over Ethernet through the adapter plugged into my screen, and 0% of the time over Wi-Fi. What made it stranger was that there were no dropped frame errors in macOS’s logs at all. This was the big hint for me: the adapter was dropping them before the computer could know.
在下载过程中,通过插入显示器的适配器进行以太网连接时,对其他有线计算机的 Ping 操作有 10% 的失败率,而通过 Wi-Fi 连接时失败率为 0%。更奇怪的是,macOS 的日志中完全没有丢帧错误。这对我来说是一个重要的提示:适配器在计算机知晓之前就已经丢弃了这些帧。
I then plugged the adapter straight into my Mac instead of the monitor, and ran an iperf3 server on my UDR 7: 2.3 Gbps. So the cable, the router and the adapter are all fine? What about fast.com? Perfect speeds there too! 2.2 down and 2.3 up when connected straight in. As soon as I connected it to the display, it was back to 600 down again.
于是我把适配器直接插到 Mac 上而不是显示器上,并在我的 UDR 7 上运行了一个 iperf3 服务器:速度为 2.3 Gbps。所以线缆、路由器和适配器都没问题?那 fast.com 呢?那里的速度也很完美!直接连接时下载 2.2 Gbps,上传 2.3 Gbps。一旦我把它连接到显示器上,下载速度又回到了 600 Mbps。
So it’s the display, right? Well, I would find out: sort of yes, sort of no, which is why I wanted to write this blog post. I couldn’t find anything online explaining the exact cause, and it’s quite a cool reason.
所以是显示器的问题,对吧?嗯,我会找出答案:算是,也算不是,这就是我想写这篇博文的原因。我在网上找不到任何解释确切原因的内容,而且这是一个非常酷的原因。
The adapter uses a Realtek RTL8156B, which on macOS binds to Apple’s generic USB networking driver. But Realtek ship their own driver on their website, so I thought I’d give that a go! I installed it and, to my surprise, it almost doubled the download speed to 1.1 Gbps, but that was still nowhere close to 2.5. First hint that it couldn’t just be the monitor’s fault.
该适配器使用 Realtek RTL8156B 芯片,在 macOS 上它绑定到苹果的通用 USB 网络驱动程序。但 Realtek 在其网站上提供了自己的驱动程序,所以我想试试看!我安装了它,令我惊讶的是,下载速度几乎翻了一番,达到 1.1 Gbps,但这仍然远未达到 2.5 Gbps。这是第一个迹象,表明这不仅仅是显示器的错。
Then I tried flow control. I had never truly looked into this before, and I think it’s quite neat to know about if you were also ignorant of it like me. Basically, when a device receives Ethernet frames it can’t keep up with, it just drops them. With flow control (it’s something your router or switch has to support), it can send the sender a “pause” frame, and the sender then buffers the data on its side, instead of the receiver (the adapter in this case) on its side. I turned it on in my UniFi console and guess what, download jumped to around 2 Gbps, with upload still at full speed! Yay! Well, not so fast…
然后我尝试了流量控制。我以前从未真正研究过这一点,如果你像我一样对此一无所知,我认为了解一下它非常有用。基本上,当设备接收到无法处理的以太网帧时,它就会丢弃它们。有了流量控制(这是你的路由器或交换机必须支持的功能),它可以向发送方发送一个“暂停”帧,然后发送方会在其一侧缓冲数据,而不是在接收方(本例中为适配器)一侧缓冲。我在我的 UniFi 控制台中打开了它,你猜怎么着,下载速度跃升至约 2 Gbps,上传速度仍然保持全速!耶!嗯,别高兴得太早……
I don’t like it always being on, because it can add latency to other systems like my gaming PC. Can you work around it? For sure, you can disable it on those computers, but it’s janky, and it’s another thing I need to remember when my Sauerbraten game starts lagging. I need fewer things to remember, considering I am 30 in a couple of months. My memory is not what it used to be.
我不喜欢它一直开启,因为它会增加其他系统(比如我的游戏 PC)的延迟。能绕过它吗?当然,你可以在那些计算机上禁用它,但这很麻烦,而且当我的 Sauerbraten 游戏开始卡顿时,这是我需要记住的另一件事。考虑到我几个月后就 30 岁了,我需要记住的事情越少越好。我的记忆力已经大不如前了。
Yeah, isn’t that weird? First of all, it looks like the port can indeed do 2.5 in both directions. I already knew that, because I get much more than that from my external SSD through the monitor’s Thunderbolt port. So the issue is not the monitor again? But it has to be!
是啊,这不是很奇怪吗?首先,看起来该端口确实可以在两个方向上达到 2.5 Gbps。我早就知道了,因为我通过显示器的雷电端口从外置 SSD 获得了远高于此的速度。所以问题又不是显示器了?但它一定是!
Well, I had another idea. How about I connect to my Linux box, which is also on 2.5, and send perfectly smooth UDP traffic at a fixed rate with flow control off? Then I can check the chip’s own counter of dropped frames:
好吧,我有了另一个主意。如果我连接到我的 Linux 机器(也是 2.5 Gbps 接口),并在关闭流量控制的情况下以固定速率发送完美的 UDP 流量会怎样?然后我可以检查芯片自己的丢帧计数器:
So basically no drops whatsoever when connected straight to my Mac, but loads of drops after about 168k frames per second (roughly 2 Gbps). Remember that number. That number comes from the adapter’s own counters: however much I sent, the number of frames it managed to hand over to the Mac each second flattened out at about 168,000, and everything above that was dropped.
基本上,直接连接到 Mac 时没有任何丢包,但在每秒约 16.8 万帧(大约 2 Gbps)之后会出现大量丢包。记住这个数字。这个数字来自适配器自己的计数器:无论我发送多少数据,它每秒成功交给 Mac 的帧数都在 16.8 万左右趋于平稳,超过这个数字的一切都被丢弃了。
Why did this not happen on my SSD? What was the only difference I could find? Bursts!
为什么我的 SSD 上没有发生这种情况?我能找到的唯一区别是什么?突发传输!
When the Mac reads data from a USB 3 device, the device sends some packets, then has to wait for the Mac to say “lgtm, send more!”. The SSD enclosure sends 16 packets before needing a go-ahead message back. The RTL8156B in my Ethernet adapter sends 4.
当 Mac 从 USB 3 设备读取数据时,设备会发送一些数据包,然后必须等待 Mac 回复“没问题,继续发送!”。SSD 外壳在需要回复确认消息之前会发送 16 个数据包。而我以太网适配器中的 RTL8156B 只发送 4 个。
Here is a diagram of my best understanding of why this is an issue. I made this diagram 100 times, and I think I can probably improve it more, but if it helps you understand the issue, I have done my job.
这是我对为什么会出现此问题的最佳理解图示。我制作了这个图表 100 次,我想我可能还能改进它,但如果它能帮助你理解这个问题,那我的工作就完成了。
As you can see, the speed of packets coming into the adapter is 2.5 Gbps. That’s what the router pushes in. The speed going out is around 2 Gbps. The reason is that if you add up the average time it takes to get the go-ahead through my monitor’s hub, which is around 7.6 µs, to the average time it takes to send 4 KB, around 8.2 µs, you can find what the maximum speed is.
如你所见,进入适配器的数据包速度是 2.5 Gbps。这就是路由器推送的速度。输出速度约为 2 Gbps。原因在于,如果你将通过显示器集线器获得确认所需的平均时间(约 7.6 微秒)与发送 4 KB 数据所需的平均时间(约 8.2 微秒)相加,你就能算出最大速度是多少。
Well, if the speed of the drain from my adapter to my Mac is half a gig slower than the speed of the input, then you can imagine the buffer getting filled more and more until it overflows. Those are dropped packets, which result in a hard backoff when the router resends them, so you drop loads in speed. And that’s the reason for all of this.
好吧,如果从适配器到 Mac 的数据流出速度比输入速度慢了 0.5 Gbps,那么你可以想象缓冲区会越来越满,直到溢出。这些就是丢弃的数据包,当路由器重新发送它们时,会导致严重的退避,从而导致速度大幅下降。这就是这一切的原因。
I have a cupboard full of USB-C Ethernet adapters. Don’t ask.
我的柜子里装满了 USB-C 以太网适配器。别问为什么。
The problem is they’re all 1 gig adapters, so any of the tests I made would not tell me anything, because the issues don’t start at 1 gig. They start at around 2… If I run my 2.5 gig adapter at 1 gig speeds, I get 1 gig downloads with the official driver. If I run it at 1.5, I get
问题是它们都是 1 Gbps 的适配器,所以我做的任何测试都无法说明问题,因为这些问题不是在 1 Gbps 时开始的。它们是在 2 Gbps 左右开始的……如果我以 1 Gbps 的速度运行我的 2.5 Gbps 适配器,使用官方驱动程序我可以获得 1 Gbps 的下载速度。如果我以 1.5 Gbps 的速度运行它,我会得到