为什么Firefox比SSH这么慢?


39

我尝试使用以下方式通过SSH启动Firefox

ssh -X user@hostname

接着

firefox -no-remote

但它非常非常慢。

我怎样才能解决这个问题?是连接问题吗?


3
除非您具有令人难以置信的高级加密级别,否则您将要使用的服务器具有很高的负载,否则它可能不是等式中的ssh部分。通常是带宽和/或延迟问题。
布拉奇利


@Gowtham,所以我可以使用:ssh -X -C user @ hostname吗?
DevOps85

Answers:


25

默认的ssh设置会使连接速度非常慢。请尝试以下操作:

ssh -YC4c arcfour,blowfish-cbc user@hostname firefox -no-remote

使用的选项是:

-Y      Enables trusted X11 forwarding.  Trusted X11 forwardings are not
         subjected to the X11 SECURITY extension controls.
 -C      Requests compression of all data (including stdin, stdout,
         stderr, and data for forwarded X11 and TCP connections).  The
         compression algorithm is the same used by gzip(1), and the
         “level” can be controlled by the CompressionLevel option for pro‐
         tocol version 1.  Compression is desirable on modem lines and
         other slow connections, but will only slow down things on fast
         networks.  The default value can be set on a host-by-host basis
         in the configuration files; see the Compression option.
 -4      Forces ssh to use IPv4 addresses only.
 -c cipher_spec
         Selects the cipher specification for encrypting the session.

         For protocol version 2, cipher_spec is a comma-separated list of
         ciphers listed in order of preference.  See the Ciphers keyword
         in ssh_config(5) for more information.

这里的要点是使用不同的加密密码(在这种情况下,arcfour比默认密码更快),并压缩要传输的数据。


注意:我距离这方面的专家非常非常遥远。上面的命令是在某处的博客文章中找到它后使用的,并且我注意到它的速度有了很大的提高。我确信以下各种评论者都知道他们在说什么,这些加密密码可能不是最好的。该答案中唯一真正相关的部分很可能是使用-C开关来压缩正在传输的数据。


11
实际上,通过更改加密设置可以提高连接的吞吐量,但是这几乎不会对延迟产生任何影响,这就是使X-over-ssh连接如此缓慢的原因...或者说不:可以实现传输文件速度更快,但是开始传输所需的时间不会改变(几乎)。这就是X协议的问题,它涉及客户端和服务器之间的许多消息和确认,因此在Internet上,几毫秒的延迟会成倍增加,直到您看到例如按钮更改其状态为止。
Ariel 2015年

8
-4(IPv4)的这里真的有关?
Cornstalks 2015年

6
该`ARCFOUR”密码已过时,顺便说一句。
恢复莫妮卡- M.施罗德

5
压缩有帮助,但行不通。Firefox要求很高。除非一方的CPU时间非常有限,否则更改密码不太可能会有所作为:对于高端设备,例如智能手机和PC,与网络延迟和带宽相比,加密/解密时间可以忽略不计。
吉尔(Gilles)'“ SO-别邪恶”

6
建议的密码是错误的方法。正如Gilles所说,如今大多数设备使用默认的AES-CTR都不会有任何问题:它非常快,特别是如果所使用的硬件具有AES指令集。RC4较弱并且已在网络上逐步淘汰,而且Blowfish-CBC不一定比AES-CTR更快。
Reid 2015年

32

远程启动某些X客户端时最大的问题之一就是X协议,而不是ssh开销!X协议要求客户端和服务器之间进行大量乒乓操作,这在远程应用程序的情况下绝对会降低性能。

尝试使用“ x2go”之类的东西(默认设置也会通过ssh进行处理),您会发现Firefox是“苍蝇”!

几个发行版提供x2go软件包开箱即用,例如Debian测试或Stable-Backports。但是,如果不是这样,请参阅http://wiki.x2go.org/doku.php/download:start,它们为许多发行版提供了预构建的二进制软件包/存储库。您应该安装x2goclient(在要“使用” firefox的计算机上)和x2goserver(应在运行firefox的计算机上),然后可以为单个X应用程序配置会话,以获取完整的桌面视图等。连接本身发生在ssh上。这是一个非常棒的工具:)

要使用它,您运行“ x2goclient”,它会启动一个GUI,您可以在其中创建一个新会话:提供服务器的dns名称,端口,ssh数据等,然后选择“会话类型”,即例如,您需要一个完整的远程KDE或GNOME桌面,或者只是一个“单个应用程序”,然后在其中输入“ firefox”。


1
我如何尝试x2go?命令
DevOps85

3
x2goserverDebian(或Ubuntu)上似乎没有软件包。另外,可以将其配置为允许隧道传输吗?例如,我使用machineX,但只能通过machineY SSH到它。x2go可以处理吗?
terdon

@terdon你是对的,我只检查了客户。但是您只需添加x2go存储库(请参阅链接wiki.x2go.org/doku.php/download:start),服务器就在那里。我不知道为什么只有客户端在Debian中。隧道:肯定有可能,但从未尝试过。我希望仅~/.ssh/config在x2go会话中配置ssh 并使用正确的(隧道式)主机名就足够了。
Ariel

@terdon:x2go会话配置中有一个“使用代理服务器进行SSH连接”(ssh / http)选项。这样也可以解决问题!
Ariel

这似乎很有趣,我会再玩一些。到目前为止,我可以确认仅配置隧道.ssh/config是不够的。我设置了它,以便ssh machineB实际上通过隧道运行,machineA但是x2go似乎看不到它。
terdon

17

我在使用ssh隧道来路由另一台计算机上的流量方面有更好的经验。设置起来非常容易,因为无论如何您都具有ssh访问权限。在计算机的终端中,键入

ssh -vv -ND 8080 user@yourserver

保持此窗口打开并观看它传递有关流过隧道的数据的一些详细消息。

在中firefox,转到首选项->高级->网络->连接:设置。

选择手动代理配置并添加SOCKS v5代理:

 SOCKS Host:   localhost    Port 8080

通过导航到例如http://whatismyipaddress.com/来检查新IP 。

您可以使用foxy代理之类的firefox插件来动态切换代理。


支持,这是使用基于NX的压缩(x2go等)的非常有效的替代方法,比摆弄ssh加密设置有用得多:)
Ariel

我一直使用ssh -L 8080:localhost:8080,但喜欢使用-ND选项,但不确定为什么使用Dinamic或Remote或Listen。顺便说一句,使用代理比使用-X更好,但是,我认为更好的方法是如果需要更多的X程序而不是Firefox,则使用VNC。
erm3nda 2016年

易于设置且有效地工作!
david.perez


0

可以改善您通过ssh进行浏览的另一件事是在Firefox中启用管道。打开about:config并更改network.http.pipelining为true。


该选项应使网页的加载速度更快,但与浏览器是否通过SSH隧道运行这一事实完全无关。无论如何,当您触摸高级选项时,请当心“但是” ...参见kb.mozillazine.org/Network.http.pipelining
Ariel

以我的经验,ssh的浏览速度变慢,流水线请求是一个很大的帮助,因为否则,任何给定的请求都必须等待先前的请求,这些请求可能会及时完成,也可能不会及时完成。我还将其与ssh复用结合在一起。它有明显的不同。在我的情况下,关闭流水线会变得非常缓慢。
丹那(Tanath)

0

您必须进行实验,以了解有助于解决特定瓶颈的因素。

对我来说,启用压缩(-C)可以将响应速度从无法使用变为明显滞后。

与某些人所说的相反,密码的选择也会产生影响。您可以找到人们在线共享基准测试,但不要以为您的结果是相同的。哪种密码最适合您取决于硬件。对我而言,我的默认密码(chacha20-poly1305@openssh.com)已被捆绑为最快的密码。

我写了一个快速脚本来在一些实际条件下对相关密码进行基准测试。注释中的解释:

#!/usr/bin/bash

# Ciphers available to you depends on the intersection of ciphers compiled 
# into your client and the ciphers compiled into your host.
# Should be manually copied from "Ciphers:" section in your `man ssh_config`
# The script will try all ciphers specified here and will gracefully skip
# ciphers unavailable in the host.
#ciphers=""
# Example:
ciphers="3des-cbc aes128-cbc aes192-cbc aes256-cbc aes128-ctr aes192-ctr aes256-ctr aes128-gcm@openssh.com aes256-gcm@openssh.com chacha20-poly1305@openssh.com"

tmp_file=tmp.bin

# Recommend to use an identity file without a passphrase.
# That way you won't have to retype the password at each iteration.
ssh_identity_file=~/.ssh/tmp_id_no_passphrase

ssh_host="user@host"

# Size of test file, before encryption.
test_file_size_megabytes=8

# Only create test file if it doesn't yet exists.
# Doesn't check if relevant variables changed, so you'll have to delete
# the $tmp_file to regenerate it.
if test ! -f $tmp_file; then
  echo "Creating random data file" \
    "(size $test_file_size_megabytes MB): $tmp_file"

  # Not the same format as the ssh ciphers.
  # Can be left as is, unless this cipher is not supported by your openssl.
  tmp_file_cipher=aes-128-cbc

  # The purpose of encrypting the $tmp_file is to make it uncompressable.
  # I do not know if that is a concern in this scenario,
  # but better safe than sorry.

  dd if=/dev/zero bs=1M count=$test_file_size_megabytes \
    | openssl enc -$tmp_file_cipher -pass pass:123 \
    > $tmp_file
fi

for cipher in $ciphers ; do
  # Benchmark each $cipher multiple times
  for i in 1 2 3 ; do
    echo
    echo "Cipher: $cipher (try $i)"
    # Time piping the $tmp_file via SSH to $ssh_host using $cipher.
    # At destination received data is discarded.
    cat $tmp_file \
      | /usr/bin/time -p \
      ssh -i $ssh_identity_file -c "$cipher" $ssh_host 'cat > /dev/null'
  done
done

# Sample output:

# Creating random data file (size 8 MB): tmp.bin
# *** WARNING : deprecated key derivation used.                                   Using -iter or -pbkdf2 would be better.                                         8+0 records in
# 8+0 records out
# 8388608 bytes (8.4 MB, 8.0 MiB) copied, 0.0567188 s, 148 MB/s

## [redacted]

# Cipher: aes256-cbc (try 3)
# Unable to negotiate with 192.168.99.99 port 22: no matching cipher found. Their offer: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
# real 0.12
# user 0.03
# sys 0.03

# Cipher: aes128-ctr (try 1)
# real 9.68
# user 0.28
# sys 0.51

# Cipher: aes128-ctr (try 2)
# real 10.85
# user 0.26
# sys 0.29

## [redacted]

您可以选择在客户端和主机是同一台计算机的情况下使用SSH连接进行测试,也可以在更现实的情况下进行测试,其中主机是进行X11转发的计算机,这将更加有用,因为性能不仅取决于客户端的性能解密,还取决于主机的性能。

如果您的Internet连接的吞吐量在基准测试过程中发生变化,则使用远程计算机进行测试可能会产生噪音,从而带来噪音。在这种情况下,可能要增加每个密码的测试次数。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.