TeamViewer 怎么这么快? [英] How is TeamViewer so fast?

查看:19
本文介绍了TeamViewer 怎么这么快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉篇幅太长,有点必要.

Sorry about the length, it's kinda necessary.

简介

我正在为 Windows Vista/7 使用 C# 4.0 开发远程桌面软件(只是为了好玩).我已经克服了一些基本障碍:我有一个强大的 UDP 消息传递系统,相对干净的程序设计,我有一个镜像驱动程序(来自 DemoForge 的免费 DFMirage 镜像驱动程序)启动并运行,我已经为所有人实现了 NAT 遍历NAT 类型,除了对称 NAT(存在于公司防火墙情况中).

I'm developing a remote desktop software (just for fun) in C# 4.0 for Windows Vista/7. I've gotten through basic obstacles: I have a robust UDP messaging system, relatively clean program design, I've got a mirror driver (the free DFMirage mirror driver from DemoForge) up and running, and I've implemented NAT traversal for all NAT types except Symmetric NATs (present in corporate firewall situations).

关于屏幕传输/共享,多亏了镜像驱动程序,我会自动收到更改屏幕区域的通知,我可以简单地将镜像驱动程序不断变化的屏幕位图编组为我自己的位图.然后我将屏幕区域压缩为 PNG 并将其从服务器发送到我的客户端.事情看起来不错,但速度还不够快.它和 VNC 一样慢(顺便说一句,我不使用 VNC 协议,只是自定义的业余协议).

Regarding screen transfer/sharing, thanks to the mirror driver, I'm automatically notified of changed screen regions and I can simply marshal the mirror driver's ever-changing screen bitmap to my own bitmap. Then I compress the screen region as a PNG and send it off from the server to my client. Things are looking pretty good, but it's not fast enough. It's just as slow as VNC (btw, I don't use the VNC protocol, just a custom amateur protocol).

从最慢的远程桌面软件到最快的,该列表通常从所有类似 VNC 的实现开始,然后上升到 Microsoft Windows 远程桌面......然后......TeamViewer.不太确定 CrossLoop、LogMeIn - 我没有使用过它们,但 TeamViewer 非常快.这简直就是活生生的.我在命令提示符上运行了 tree 命令,它以 20 毫秒的延迟更新.我浏览网页的速度只比笔记本电脑慢几毫秒.在 Visual Studio 中垂直滚动代码有 50 毫秒的延迟时间.想一想 TeamViewer 的屏幕传输解决方案必须有多强大才能完成这一切.

From the slowest remote desktop software to the fastest, the list usually begins at all VNC-like implementations, then climbs up to Microsoft Windows Remote Desktop...and then...TeamViewer. Not quite sure about CrossLoop, LogMeIn - I haven't used them, but TeamViewer is insanely fast. It's quite literally live. I ran a tree command on Command Prompt and it updated with 20 ms delay. I can browse the web just a few milliseconds slower than on my laptop. Scrolling code vertically in Visual Studio has 50 ms lag time. Think about how robust TeamViewer's screen-transfer solution must be to accomplish all this.

VNC 使用基于轮询的挂钩来检测屏幕变化,并在最糟糕的情况下进行暴力屏幕捕获/比较.在他们最好的情况下,他们使用像 DFMirage 这样的镜像驱动程序.我就是这个水平.他们使用一种叫做 RFB 协议的东西.

VNCs use poll-based hooks for detecting screen change and brute force screen capturing/comparing at their worst. At their best, they use a mirror driver like DFMirage. I'm at this level. And they use something called the RFB protocol.

Microsoft Windows 远程桌面显然比 VNC 高出一步.我从 StackOverflow 的某个地方听说 Windows 远程桌面不发送屏幕位图,而是发送实际的绘图命令.这非常棒,因为它可以只发送简单的文本(在这个坐标处绘制这个矩形并用这个渐变着色)!远程桌面确实非常快 - 它是在家工作的标准方式.它使用称为 RDP 协议的东西.

Microsoft Windows Remote Desktop apparently goes one step higher than VNC. I heard, from somewhere on StackOverflow, that Windows Remote Desktop doesn't send screen bitmaps, but actual drawing commands. That's quite brilliant, because it can just send simple text (draw this rectangle at this coordinate and color it with this gradient)! Remote Desktop really is pretty fast - and it's the standard way of working from home. And it uses something called the RDP protocol.

现在 TeamViewer 对我来说完全是个谜.显然,他们发布了版本 2 的源代码(截至 2012 年 2 月,TeamViewer 是版本 7).人们读过它并说第 2 版毫无用处 - 它只是对具有自动 NAT 遍历的 VNC 的一些改进.

Now TeamViewer is a complete mystery to me. Apparently, they released their source code for Version 2 (TeamViewer is Version 7 as of February 2012). People have read it and said that Version 2 is useless - that it's just a few improvements over VNC with automatic NAT traversal.

但是第 7 版……现在速度快得离谱了.我的意思是,它实际上比 Windows 远程桌面更快.我已经使用 TeamViewer 流式传输 DirectX 3D 游戏(速度为 1 fps,但 Windows 远程桌面甚至不允许 DirectX 运行).

But Version 7...it's ridiculously fast now. I mean, it's actually faster than Windows Remote Desktop. I've streamed DirectX 3D games with TeamViewer (at 1 fps, but Windows Remote Desktop doesn't even allow DirectX to run).

顺便说一下,TeamViewer在没有镜像驱动程序的情况下完成了所有这些工作.有一个安装选项,它会更快一点.

By the way, TeamViewer does all this without a mirror driver. There is an option to install one, and it gets just a bit faster.

问题

我的问题是,TeamViewer 怎么这么快? 一定不可能.如果您在 24 位深度下获得 1920 x 1080 分辨率(16 位深度会明显难看),那仍然是 6,220,800 字节的原始数据.即使使用 libjpeg-turbo(大公司使用的最快的 JPG 压缩库之一),将其压缩到 30KB(让我们非常慷慨),通过 TeamViewer 的服务器进行路由也需要时间(TeamViewer 通过简单地代理流量绕过公司对称 NAT他们的服务器).并且 libjpeg-turbo 压缩需要时间来压缩.对我来说,高质量的 JPG 压缩需要 175 毫秒才能获得完整的 1920 x 1080 屏幕截图.如果主机的计算机运行 Atom 处理器,这个数字就会上升.我只是不明白 TeamViewer 是如何将屏幕传输优化得如此出色的.同样,小尺寸图像可能会被高度压缩,但压缩至少需要几十毫秒.大尺寸的图像不需要时间来压缩,但需要很长时间才能通过.不知何故,TeamViewer 完成了整个过程以获得大约 20-25 帧每秒.我使用了网络监视器,TeamViewer 在 500 Kbps 和 1 Mbps 的速度下仍然没有延迟(在该传输速率下,VNC 软件延迟了几秒钟).在我的 tree 命令提示符测试期间,TeamViewer 以 1 Mbps 的速率接收入站数据,并且仍在运行 5-6 fps.VNC 和远程桌面不这样做.那么,如何?

My question is, how is TeamViewer so fast? It must not be possible. If you've got 1920 by 1080 resolution at even 24 bit depth (16 bit depth would be noticeably ugly), thats still 6,220,800 bytes raw. Even using libjpeg-turbo (one of the fastest JPG compression libraries used by large corporations), compressing it down to 30KB (let's be extremely generous), would take time to route through TeamViewer's servers (TeamViewer bypasses corporate Symmetric NATs by simply proxying traffic through their servers). And that libjpeg-turbo compression would take time to compress. High-quality JPG compression takes 175 milliseconds for a full 1920 by 1080 screenshot for me. And that number goes up if the host's computer runs an Atom processor. I simply don't understand how TeamViewer has optimized their screen transfer so well. Again, small-size images might be highly compressed, but take at least tens of milliseconds to compress. Large-size images take no time to compress, but take a long time to get through. Somehow, TeamViewer completes this entire process to get roughly 20-25 frames per second. I've used a network monitor, and TeamViewer is still lagless at speeds of 500 Kbps and 1 Mbps (VNC software lag for a few seconds at that transfer rate). During my tree Command Prompt test, TeamViewer was receiving inbound data at a rate of 1 Mbps and still running 5-6 fps. VNC and remote desktop don't do that. So, how?

答案会有些复杂和错综复杂,所以如果你只想说这是因为他们使用 UDP 而不是 TCP,请不要发布你的 0.02 美元(你相信他们真的会这样做吗?使用 TCP 也一样成功).

The answers will be somewhat complicated and intricate, so please don't post your $0.02 if you're only going to say it's because they use UDP instead of TCP (would you believe they actually do use TCP just as successfully though).

我希望 StackOverflow 上的某个地方有 TeamViewer 开发人员.

I'm hoping there's a TeamViewer developer somewhere here on StackOverflow.

可能的答案

有人回复后会更新.

  1. 首先,我的想法是,TeamViewer 具有非常精细的网络控制.例如,他们将大数据包拆分为刚好低于 MTU 大小,并且从不浪费行程.他们可能有各种花哨的钩子来检测屏幕变化以及极快的 XOR 图像比较.

推荐答案

这里最根本的可能是您不想传输静态图像,而只是更改图像,这本质上是类似于视频流.

The most fundamental thing here probably is that you don't want to transmit static images but only changes to the images, which essentially is analogous to video stream.

我最好的猜测是一些非常有效(并且高度专业化和优化)的运动补偿算法,因为通用桌面使用的大部分实际变化是元素的线性移动(滚动文本、移动窗口、等反对元素的转换).

My best guess is some very efficient (and heavily specialized and optimized) motion compensation algorithm, because most of the actual change in generic desktop usage is linear movement of elements (scrolling text, moving windows, etc. opposed to transformation of elements).

1 FPS 的 DirectX 3D 性能似乎在一定程度上证实了我的猜测.

The DirectX 3D performance of 1 FPS seems to confirm my guess to some extent.

这篇关于TeamViewer 怎么这么快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆