识别下载视频时的慢跳

xra*_*alf 2 command-line networking

我正在下载视频如下

$ youtube-dl url_to_video
Run Code Online (Sandbox Code Playgroud)

下载文件很慢

33.1% of 301.31MiB at 19.75KiB/s ETA 02:54:03

它通常更快。

您能否通过命令行工具识别瓶颈在哪里(速度迅速减慢的跳跃)?与第 X+1 跳相比,命令行工具应该能够显示第 X 跳的速度减慢。

roa*_*ima 5

如果你有工具timeouttraceroutebing安装了这个脚本可能会有所帮助。

这样做是向下迭代一个traceroute列表,并将“当前”主机的数据包速度与前一个主机的数据包速度进行比较。然后将此差异(如果有)报告给用户。

它需要一个目标主机名。由于您正在使用,因此youtube-dl您需要获取它以告诉您提供视频的服务器的主机名。以下是导出主机名的用法示例:

youtube-dl --get-url --simulate 'https://www.youtube.com/watch?v=OQZlqeUBbck' 2>/dev/null |
    cut -d/ -f3
Run Code Online (Sandbox Code Playgroud)

对我来说,这让我得到了主机名r7---sn-aiglln76.googlevideo.com。有了它,您就可以运行脚本(如下)。运行需要一点时间,在第一分钟左右,您可能根本没有任何输出。

#!/bin/bash
#
target="$1"    # Hostname
test -z "$target" && read -p "Target destination: " target

phop=0 first=y
timeout 90 traceroute "$target" |
    awk '$1+0' |
    while read hop rhost rip junk
    do
        test "$rhost" == '*' && continue
        rip="${rip//[()]/}"

        # Is the host reachable?
        ping -q -c1 -w4 "$rip" >/dev/null 2>&1 || continue

        if test -n "$rhost" -a -n "$phost"
        then
            test -n "$first" && { printf "Hops\tRoute\n"; first=; }

            # Test the link speed between these two hosts
            bing=$(
                bing -c1 -e20 "$pip" "$rip" 2>/dev/null |
                tail -1 |
                awk '!/zero/ {print $2}'
            )

            # Report any useful result
            printf "%2d-%2d\t%s (%s) to %s (%s): %s\n" "$phop" "$rhop" "$phost" "$pip" "$rhost" "$rip" "${bing:-no measured difference}"
        fi

        # Save the current host for the next hop comparison
        phop="$rhop" phost="$rhost" pip="$rip"
    done
Run Code Online (Sandbox Code Playgroud)

在英国测试运行到远程办公室的一些输出:

Hops    Route
 1- 4   10.20.1.254 (10.20.1.254) to aaa.obscured (): no measured difference
 4- 5   be200.asr01.thn.as20860.net (62.128.207.218) to 195.66.227.42 (195.66.227.42): no measured difference
 5- 6   195.66.227.42 (195.66.227.42) to core3-hu0-1-0-5.faraday.ukcore.bt.net (62.172.103.132): no measured difference
 6- 7   core3-hu0-1-0-5.faraday.ukcore.bt.net (62.172.103.132) to 195.99.127.60 (195.99.127.60): no measured difference
 7- 8   195.99.127.60 (195.99.127.60) to acc1-10gige-0-2-0-0.bm.21cn-ipp.bt.net (109.159.248.25): 512.000Mbps
 8- 9   acc1-10gige-0-2-0-0.bm.21cn-ipp.bt.net (109.159.248.25) to 109.159.248.99 (109.159.248.99): no measured difference
 9-14   109.159.248.99 (109.159.248.99) to bbb.obscured (): 717.589Kbps
Run Code Online (Sandbox Code Playgroud)

由此可以看出,我的流量在 9 到 14 之间似乎有很大的放缓,在那里我们下降到典型的 ADSL 上游。

我应该指出,bing如果两个远程点的连接速度超过您与这些点的可用连接,则无法测量它们之间的速度差异。我的连接是 512Mbps,所以我无法测量大多数运营商链接。