curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: [curl/curl] 04b61f: progress: fix rate-limit for high speed transfers

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 21 Mar 2018 00:42:38 +0100 (CET)

On Tue, 20 Mar 2018, Ben Greear wrote:

> I guess I should share the algorithm I use, it is basically:
>
> calculate diff between last time I checked and now.
> If < 1ms, return
>
> Calculate the amount of bits that should be allowed over the last time
> interval. Add those to the 'bucket'.
>
> When it is time to determine if rate is too high or not, check if there are
> enough bits in the bucket. If there are, then proceed, else wait until
> there are enough bits gathered up.
>
> To decrease bursts after an idle time, you have to limit the bucket to a
> reasonable amount (like 10-15ms, or at least the time it takes to
> send/receive 1 or two of your 'data units'.

First, I test this with my 3000MB/sec transfers from localhost and I try to
limit to speeds like 10K, 100K, 100MB, 1000MB etc.

In PERFORM state:

  based on the delta time and delta size, figure out how long time to wait

  if deemed we should wait
    store a new timestamp and sizestamp for next wait-check - if the delta
    time is larger than MIN_RATE_LIMIT_PERIOD

    change to TOOFAST state

In TOOFAST state (when we've waited enough)

  based on the delta time and delta size, figure out how long time to wait

  if deemed we should still wait, set a new timer and stick in the state

  if deemed we're done waiting
    store a new timestamp and sizestamp for next wait-check - if the delta
    time is larger than MIN_RATE_LIMIT_PERIOD

    change to PERFORM state

I don't spot much of a difference between MIN_RATE_LIMIT_PERIOD set to 1 or
400 ms but I fgiure the first or second call can get out of the range quite a
bit if there's a bit of a jitter in the transfer speed.

In reality I suppose the important thing is to prevent the 0ms period so 1ms
should be good enough and it will basically then even itself out since it'll
then wait for the same period assuming the math precision is good enough.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2018-03-21