curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Large download speed deviations for CURLOPT_MAX_RECV_SPEED_LARGE in 8.4.0

From: Dmitry Karpov via curl-library <>
Date: Fri, 8 Dec 2023 19:42:39 +0000

Yes, it has the same effect.
I was thinking about the same way but was hesitating to make the "max_recv" go below zero after "max_recv -= blen", but now I see that it is OK and such cases are properly covered.

Your solution is smaller and better than mine, we probably just need to add a comment explaining why we set the "max_recv" to zero if the speed limit is set.

Besides improved speed precision, this solution also makes CPU less "bursty" when the speed limit is set,
because data reading and processing times are now better mixed with smaller waiting times imposed by the speed limit.

Dmitry Karpov

-----Original Message-----
From: Daniel Stenberg <>
Sent: Friday, December 8, 2023 7:29 AM
To: Dmitry Karpov via curl-library <>
Cc: Dmitry Karpov <>
Subject: [EXTERNAL] Re: Large download speed deviations for CURLOPT_MAX_RECV_SPEED_LARGE in 8.4.0

On Tue, 5 Dec 2023, Dmitry Karpov via curl-library wrote:

> With this patch, I was able to get quite precise speed limitations
> (under 0.5% on average) for different socket buffers and speed limits.

Isn't this the same effect with a smaller change?

--- a/lib/transfer.c
+++ b/lib/transfer.c
_at__at_ -430,12 +430,11 _at__at_ static CURLcode readwrite_data(struct Curl_easy *data,
    CURLcode result = CURLE_OK;
    char *buf;
    size_t blen;
    size_t consumed;
    int maxloops = 100;
- curl_off_t max_recv = data->set.max_recv_speed?
- data->set.max_recv_speed : CURL_OFF_T_MAX;
+ curl_off_t max_recv = data->set.max_recv_speed ? 0 : CURL_OFF_T_MAX;
    bool data_eof_handled = FALSE;

    *done = FALSE;
    *comeback = FALSE;

  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
Received on 2023-12-08