Skip to content

download ratelimit finetune#20228

Closed
icing wants to merge 1 commit intocurl:masterfrom
icing:dl-rlimit-finetune
Closed

download ratelimit finetune#20228
icing wants to merge 1 commit intocurl:masterfrom
icing:dl-rlimit-finetune

Conversation

@icing
Copy link
Contributor

@icing icing commented Jan 9, 2026

When a download size is known and rate limiting is in effect, adjust the duration of each measurement step and its rate for maximum precision.

Since it is unpredictable how long the last bytes of a download will take, download speed can be thrown off if the "last bytes" are a significant amount of the total download. Make the "last bytes" small in comparison to the rest and "stretch" the rate limit intervals to accommodate the difference.

Fix ngtcp2 receive data acknowledgements to be based on a local window size tracking. This allows window updates controlled by rate limits.

Fix ratelimit wait time calculation to accommodate negative tokens.

Add ratelimit measurements in scorecard. Examples:

> python3 tests/http/scorecard.py -d --download-count=5 --download-sizes=128kb,512kb,1mb,10mb --download-parallel=1 --limit-rate=$speed h1

Download Speed, limit=256.000 KB/s, from httpd/2.4.66
   size            serial(5) [cpu/rss]
  128KB  257.401 KB/s, +0.5% [0.6%/12MB]
  512KB  257.676 KB/s, +0.7% [0.1%/12MB]
    1MB  256.890 KB/s, +0.3% [0.1%/12MB]
   10MB  256.147 KB/s, +0.1% [0.0%/12MB]

Download Speed, limit=500.000 KB/s, from httpd/2.4.66
   size            serial(5) [cpu/rss]
  128KB  501.302 KB/s, +0.3% [1.5%/12MB]
  512KB  502.791 KB/s, +0.6% [0.3%/12MB]
    1MB  501.455 KB/s, +0.3% [0.2%/12MB]
   10MB  500.431 KB/s, +0.1% [0.1%/12MB]

Download Speed, limit=800.000 KB/s, from httpd/2.4.66
   size            serial(5) [cpu/rss]
  128KB  801.391 KB/s, +0.2% [2.6%/12MB]
  512KB  802.930 KB/s, +0.4% [0.5%/12MB]
    1MB  801.564 KB/s, +0.2% [0.3%/12MB]
   10MB  800.357 KB/s, +0.0% [0.1%/12MB]

Download Speed, limit=1024.000 KB/s, from httpd/2.4.66
   size             serial(5) [cpu/rss]
  128KB  1025.588 KB/s, +0.2% [3.7%/12MB]
  512KB  1027.610 KB/s, +0.4% [0.6%/12MB]
    1MB  1024.773 KB/s, +0.1% [0.4%/12MB]
   10MB  1024.813 KB/s, +0.1% [0.1%/12MB]

Download Speed, limit=5120.000 KB/s, from httpd/2.4.66
   size             serial(5) [cpu/rss]
  128KB  4959.631 KB/s, -3.1% [25.9%/11MB]
  512KB  5048.880 KB/s, -1.4% [5.3%/12MB]
    1MB  5086.098 KB/s, -0.7% [2.5%/12MB]
   10MB  5114.312 KB/s, -0.1% [0.5%/12MB]

@icing icing requested a review from bagder January 9, 2026 12:51
@icing icing marked this pull request as draft January 10, 2026 14:04
@icing icing force-pushed the dl-rlimit-finetune branch from c008b2d to 1538409 Compare January 12, 2026 15:38
@github-actions github-actions bot added the tests label Jan 12, 2026
@icing icing force-pushed the dl-rlimit-finetune branch from 91ee24f to f8002b7 Compare January 14, 2026 13:06
@icing
Copy link
Contributor Author

icing commented Jan 14, 2026

And now with additional fixes that make h2/h3 work correctly:

Download Speed (h2), limit=800.000 KB/s, from httpd/2.4.66
   size            serial(2) [cpu/rss]
  128KB  792.025 KB/s, -1.0% [10.9%/11MB]
  512KB  801.773 KB/s, +0.2% [2.1%/12MB]
    1MB  801.091 KB/s, +0.1% [1.1%/12MB]
   10MB  800.302 KB/s, +0.0% [0.2%/12MB]

Download Speed (h3), limit=800.000 KB/s, from nghttpx: https:62578 [backend httpd/2.4.66]
   size            serial(2) [cpu/rss]
  128KB  792.184 KB/s, -1.0% [10.6%/12MB]
  512KB  800.064 KB/s, +0.0% [2.4%/12MB]
    1MB  800.376 KB/s, +0.0% [1.2%/12MB]
   10MB  800.174 KB/s, +0.0% [0.5%/12MB]

@icing icing marked this pull request as ready for review January 14, 2026 16:09
    When a download size is known and rate limiting is in effect, adjust the
    duration of each measurement step and its rate for maximum precision.

    Since it is unpredictable how long the last bytes of a download will take,
    download speed can be thrown off if the "last bytes" are a significant
    amount of the total download. Make the "last bytes" small in comparision
    to the rest and "stretch" the rate limit intervals to accommodate
    the difference.

    Fix ngtcp2 receive data acknowldgements to be based on a local window
    size tracking. This allows window updates controlled by rate limits.

    Fix ratelimit wait time calculation to accomodate negative tokens.

    h3 rate limit, update timeers

    Make download rate limits work correctly in ngtcp2. Fix multi
    handling of rate limits to set a timer for when limits will update
    again.

    Without running the transfer on limit updates, protocols like h2/h3
    may stall if the server does not send due to stream windows being
    too small.

    scorecard: measure download speedlimits

    When running scorecard with --limit-rate=n, show the reported download
    speed averages plus percentage deviation from the limit.
@icing icing force-pushed the dl-rlimit-finetune branch from 58a8def to db5f0a5 Compare January 15, 2026 11:00
Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ripe for merge now, right?

@icing
Copy link
Contributor Author

icing commented Jan 16, 2026

Yes, please.

@bagder bagder closed this in 1a57302 Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants