我一直在使用Emacs Tramp进行远程开发,但是发现它运行速度非常慢。每次保存文件需要大约10秒钟才能完成保存。所以现在我改用rsync来远程传输文件,速度快多了,只需一秒钟左右,而且本地保存的速度也非常快。是否有任何Tramp配置选项可以让它像命令行上的rsync一样快?即使我看到如此糟糕的性能,是否使用Tramp仍然有什么优点,而不是使用rsync?
虽然tramp可以配置使用大量的传输方法,但我想你正在使用ssh连接到远程服务器。
我认为完成操作所需的大部分时间来自于建立连接和身份验证。如果您使用的是足够新的OpenSSH版本,则可以通过使用连接共享功能来帮助解决此问题,请参见ssh_config(5)中的ControlMaster。
我建议您尝试
ControlMaster auto
并查看是否改善了情况。
如果你正在使用tramp进行ssh/scp功能,你会发现打开一个持久的SSH连接将使tramp操作更快:它们将重用现有的连接而不是每次创建一个新连接,从而削减了大量的加密开销而不影响安全性。请参阅关于SSH ControlMaster 功能的文章。
tramp-methods
变量,您将看到有现有的方法可以启用 ControlMaster。rsyncc
和 scpc
两种方法。tramp-default-method
。shell
RET 在远程服务器上打开了一个 shell,命令像 M-x rgrep
RET 和 M-x find-grep-dired
RET 将在远程服务器上运行查找+ grep。我认为这通常适用于调用 shell 命令的函数。tramp-methods
中没有任何scpc
或rsyncc
,但我发现变量tramp-ssh-controlmaster-options
被插入到%c
中,而常规的ssh
方法使用%c
。 - unhammertramp-use-ssh-controlmaster-options
。 - phils您是否熟悉gnu.org上提到使用rsync的tramp文档中的一节?其中一部分内容如下:
5.3 External transfer methods
The external transfer methods operate through multiple channels, using the remote shell connection for many actions while delegating file transfers to an external transfer utility.
This saves the overhead of encoding and decoding that multiplexing the transfer through the one connection has with the inline methods.
...
rsync — ssh and rsync Using the ssh command to connect securely to the remote machine and the rsync command to transfer files is almost identical to the scp method.
While rsync performs much better than scp when transferring files that exist on both hosts, this advantage is lost if the file exists only on one side of the connection. The rsync based method may be considerably faster than the rcp based methods when writing to the remote system. Reading files to the local machine is no faster than with a direct copy. This method supports the ‘-p’ hack.
既然你之前说在特定服务器上有问题,那就检查一下出问题的机器上的sshd配置文件。它可能是/etc/ssh/sshd_config这样的路径。
找到一个名为“UseDNS”的配置选项。将其设置为“No”。
看看这是否可以加快速度。如果是这样,那么ssh可能会超时等待反向DNS查找,而你可能并不关心这个。
最近我开始使用sshfs,这样远程文件就可以在本地进行编辑。它适用于Linux、Mac和Unix系统,并将ssh部分放在一个命令中而不是每次访问时都需要输入。而且完全存在于用户空间。
sftp
添加到tramp-gvfs-methods
中,以便TRAMP使用GNOME的GVFS连接到sftp服务器,这可能更快/更方便。