在退出之前,您会期望这个命令需要多长时间?
wget --timeout=1 --tries=2 "http://www.google.com:81/not-there"
我期望1秒的超时和2次尝试将意味着2秒,但它需要6.025秒
wget --timeout=1 --tries=2 "http://www.google.com:81/not-there" --2017-04-27 16:49:12--http://www.google.com:81/not-there Resolving www.google.com (www.google.com)... 209.85.203.105, 209.85.203.103, 209.85.203.99, ... Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|2a00:1450:4009:80d::2004|:81... failed: Network is unreachable.
我不知道为什么6次退出。
这似乎是tries
重试。 如果我设置--retry-connrefused
它至less做了重试,但总的时间是不是我所期望的。 我希望能够决定在超时时间内应该尝试多less次。
编辑 :
在@Socowi的build议之后,我尝试使用waitretry和retry-connrefused结合起来,得到相同的行为:
$ wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there" --2017-04-27 20:29:47-- http://www.google.com:81/not-there Resolving www.google.com (www.google.com)... 2a00:1450:400b:c00::68, 209.85.203.99, 209.85.203.147, ... Connecting to www.google.com (www.google.com)|2a00:1450:400b:c00::68|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out. Retrying. --2017-04-27 20:29:54-- (try: 2) http://www.google.com:81/not-there Connecting to www.google.com (www.google.com)|2a00:1450:400b:c00::68|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out. Giving up.
编辑两个
当两个相同的命令performance不同时,我感到非常困惑。
root@8c59d6dd05fe:/var/www/html# wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there" converted 'http://www.google.com:81/not-there' (ANSI_X3.4-1968) -> 'http://www.google.com:81/not-there' (UTF-8) --2017-04-27 19:50:28-- http://www.google.com:81/not-there Resolving www.google.com (www.google.com)... 216.58.211.164, 2a00:1450:4009:805::2004 Connecting to www.google.com (www.google.com)|216.58.211.164|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|2a00:1450:4009:805::2004|:81... failed: Cannot assign requested address. Retrying. --2017-04-27 19:50:29-- (try: 2) http://www.google.com:81/not-there Connecting to www.google.com (www.google.com)|216.58.211.164|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|2a00:1450:4009:805::2004|:81... failed: Cannot assign requested address. Giving up. root@8c59d6dd05fe:/var/www/html# wget --timeout=1 --waitretry=0 --tries=2 --retry-connrefused "http://www.google.com:81/not-there" converted 'http://www.google.com:81/not-there' (ANSI_X3.4-1968) -> 'http://www.google.com:81/not-there' (UTF-8) --2017-04-27 19:50:35-- http://www.google.com:81/not-there Resolving www.google.com (www.google.com)... 209.85.203.104, 209.85.203.147, 209.85.203.106, ... Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|2a00:1450:400b:c03::68|:81... failed: Cannot assign requested address. Retrying. --2017-04-27 19:50:41-- (try: 2) http://www.google.com:81/not-there Connecting to www.google.com (www.google.com)|209.85.203.104|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.147|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.106|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.103|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.105|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|209.85.203.99|:81... failed: Connection timed out. Connecting to www.google.com (www.google.com)|2a00:1450:400b:c03::68|:81... failed: Cannot assign requested address. Giving up.
我以为自己有点疯狂,但只有@Socowi在评论中指出,每次重试的IP都不一样,才会被点击。 这取决于可能的IP被返回的数量。 我看到的幻数7(重试)是IP选项的数字。 当我只select一个特定的IP时,它只会尝试一次。
您的wget似乎将URL解析为多个IP地址,如wget
输出的第二行所示。 然后每个IP在指定的超时时间内进行测试。 不幸的是,我还没有找到任何选项将DNS查找限制在一个地址上,或者将所有IP的总超时设置在一起。 但是你可以尝试使用"<googles ip address>:81/not-there"
而不是URL。
正如你已经发现的那样,设置--retry-connrefused
让wget
甚至在一个“ 连接被拒绝 ”错误之后重试。 每个重试都使用指定的超时,但在重试之间会有一个暂停,每次重试之后都会变得更长。
wget --timeout=1 --tries=5 --retry-connrefused URL
做类似的事情
try to connect for 1 second failed -> wait 1 second try to connect for 1 second failed -> wait 2 seconds try to connect for 1 second failed -> wait 3 second try to connect for 1 second failed -> wait 4 second try to connect for 1 second
因此,该命令需要tries * timeout + 1 + 2 + ... + (tries - 1)
秒。 这个行为是在man wget
下的man wget
选项中指定的,它允许你改变它:)
–waitretry =秒
如果您不希望Wget在每次检索之间等待,而只是在重试失败的下载之间,则可以使用此选项。 Wget将使用线性退避,在给定文件第一次故障后等待1秒,然后在第二次故障之后等待2秒 ,直到指定的最大秒数。默认情况下,Wget会假定值为10秒。
我想你想用类似的东西
wget --timeout=1 --waitretry=0 --tries=5 --retry-connrefused URL
这消除了两次重试之间的暂停,导致timeout * tries
的总时间。