"curl --retry-max-time <seconds>"如何工作?


我不知道

--retry-max-time是如何计算的。如果我下载文件file.txt

curl --max-time 10 --retry 3 --retry-delay 5 --retry-max-time 32 'http://www.site.com/download/file.txt'

  • [ 0- 2] 下载50%文件需要2s,而且速度不再快。
  • [ 2-10] 再等8s,还是没有速度,超时,会重试
  • [10-15] 它在重试 #1 之前等待5s
  • [15-25] 仍然没有速度,将重试
  • [25-30] 它等待5s,然后重试 #2
  • [30-34] 下载33%文件需要4s,而且速度不再快。
  • [34-40] 它等待另一个6s,仍然没有速度,超时

此时(40scurl会停止重试吗?

retry timer是什么时候开始和停止的?


   --retry-max-time <seconds>
          The  retry  timer  is reset before the first transfer attempt. Retries will be done as usual (see --retry) as
          long as the timer hasn't reached this given limit. Notice that if the timer hasn't  reached  the  limit,  the
          request  will be made and while performing, it may take longer than this given time period. To limit a single
          request´s maximum time, use -m, --max-time.  Set this option to  zero  to  not  timeout  retries.  (Added  in
          7.12.3)
curl --connect-timeout 5 
     --max-time 10 
     --retry 5 
     --retry-delay 0 
     --retry-max-time 60 
     'http://www.site.com/download/file.txt'

|<---0---->| {<---1---->|  |<---2---->|    |<---3---->|   |<---4---->|   }            |<---5---->|
|....==    | {...==     |  |....==    |    |.....|        |..=== =   |   }
             {                                                           }

表示法

=====  downloading...       (file size is 5)
.....  --connect-timeout 5
|<->|  --max-time 10
<-5->  --retry 5
>| |<  --retry-delay 0      ([default] exp backoff algo)
{   }  --retry-max-time 60  (GAME OVER)

注意

  • 重试延迟 1、2、4、8 ...
  • 重试 #3 连接超时
  • 重试 #5 永远不会发生
  • 下载在 END 时失败(71 秒)

让我试着澄清一下。

当 curl 决定重试(因为使用了 --retry 并且条件允许重试)并设置了--retry-max-time时,curl 会检查自操作开始以来经过的总时间是否超过了--retry-max-time。如果没有,它将允许再次重试。

所以在上面的命令行中:如果总时间在考虑重试时小于 32 秒,它将再次重试。如果总时间超过 32 秒,则不会再重试。

最新更新