在我的速度测试中计算正确的 MBit/s

在我的速度测试中计算正确的 MBit/s

我知道wget通常会在摘要中显示速度。但是在我的小型 OpenWRT shell 中,我想测试下载 100MB 需要多长时间

t=$(date +"%s")
wget http://speedtest.netcologne.de/test_100mb.bin -O ->/dev/null
echo -n "mBit/s:"; expr 8 \* 100 / $(($(date +"%s")-$t))

解释:

  1. 将时间戳存储在 $t 中
  2. 下载 100mb 但不存储任何内容
  3. 计算8 * 100mb / $t

我是否需要添加更多计算才能真正获得 MBit/s?也许乘以或除以 1.024 几次?

我还注意到,通过此链接使用 wget 下载并不总是正好 100mb,如何在不将其存储为文件的情况下获得正确的下载 mb 大小?

答案1

Content-Length许多(不是全部)站点在标题字段中给出了大小。您可以使用 获取该信息wget -S,但似乎没有选项来禁止下载。 curl -D也会做这个。

但是,您可以使用 lynx 获取标头,例如,

$ lynx -dump -head http://speedtest.netcologne.de/test_100mb.bin
HTTP/1.1 404 Not Found
Server: nginx/1.6.2
Date: Sat, 13 Aug 2016 14:35:45 GMT
Content-Type: text/html
Content-Length: 168
Connection: close

这比以下更简洁wget

$ wget -S http://speedtest.netcologne.de/test_100mb.bin
--2016-08-13 10:29:51--  http://speedtest.netcologne.de/test_100mb.bin
Resolving speedtest.netcologne.de (speedtest.netcologne.de)... 78.35.18.142
Connecting to speedtest.netcologne.de (speedtest.netcologne.de)|78.35.18.142|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 404 Not Found
  Server: nginx/1.6.2
  Date: Sat, 13 Aug 2016 14:29:51 GMT
  Content-Type: text/html
  Content-Length: 168
  Connection: keep-alive
2016-08-13 10:29:51 ERROR 404: Not Found.

给定的 URL 无效。对于实时网站,会发生更多情况:

$ lynx -head -dump http://unix.stackexchange.com
HTTP/1.1 200 OK
Cache-Control: public, max-age=60
Content-Length: 77651
Content-Type: text/html; charset=utf-8
Expires: Sat, 13 Aug 2016 14:39:01 GMT
Last-Modified: Sat, 13 Aug 2016 14:38:01 GMT
X-Frame-Options: SAMEORIGIN
X-Request-Guid: 4da57e2b-c682-4e63-8fad-9415b23cd43e
Accept-Ranges: bytes
Date: Sat, 13 Aug 2016 14:38:01 GMT
Via: 1.1 varnish
Connection: close
X-Served-By: cache-iad2627-IAD
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1471099081.842119,VS0,VE17
Vary: *
X-DNS-Prefetch-Control: off
Set-Cookie: prov=31367c00-2e03-4760-79fe-d4e13e52792e; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly

相对

$ wget -S http://unix.stackexchange.com
--2016-08-13 10:38:51--  http://unix.stackexchange.com/
Resolving unix.stackexchange.com (unix.stackexchange.com)... 151.101.129.69, 151.101.193.69, 151.101.1.69, ...
Connecting to unix.stackexchange.com (unix.stackexchange.com)|151.101.129.69|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Cache-Control: public, max-age=60
  Content-Type: text/html; charset=utf-8
  Expires: Sat, 13 Aug 2016 14:39:51 GMT
  Last-Modified: Sat, 13 Aug 2016 14:38:51 GMT
  X-Frame-Options: SAMEORIGIN
  X-Request-Guid: d7279b7d-1605-49dc-9851-4658308bf6b1
  Content-Length: 77662
  Accept-Ranges: bytes
  Date: Sat, 13 Aug 2016 14:38:51 GMT
  Via: 1.1 varnish
  Connection: keep-alive
  X-Served-By: cache-iad2633-IAD
  X-Cache: MISS
  X-Cache-Hits: 0
  X-Timer: S1471099131.339794,VS0,VE16
  Vary: *
  X-DNS-Prefetch-Control: off
  Set-Cookie: prov=77b452f3-9269-f933-e756-b4eb3010dc30 domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
Length: 77662 (76K) [text/html]
Saving to: `index.html.1'

100%[======================================>] 77,662      --.-K/s   in 0.02s   

2016-08-13 10:38:51 (3.54 MB/s) - `index.html.1' saved [77662/77662]

相关内容