New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the download file is less than the limit speed, it cannot be limited #2371

Closed
liupeidong0620 opened this Issue Mar 9, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@liupeidong0620

liupeidong0620 commented Mar 9, 2018

I did this

Download file size:

[root@california src]# du -sh curl-7.58.0.tar.gz
3.8M	curl-7.58.0.tar.gz

Problems with the new version:

[root@california src]# ./curl -V
curl 7.57.0 (x86_64-pc-linux-gnu) libcurl/7.57.0 OpenSSL/1.0.2h
Release-Date: 2017-11-29
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL TLS-SRP UnixSockets HTTPS-proxy

[root@california src]# time ./curl https://curl.haxx.se/download/curl-7.58.0.tar.gz -O --limit-rate 4M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 3788k  100 3788k    0     0  3788k      0  0:00:01 --:--:--  0:00:01 28.6M

real	0m0.145s
user	0m0.033s
sys	0m0.021s

Real download time: real 0m0.145s

I expected the following

Correct performance

[root@california src]# ./curl -V
curl 7.36.0 (x86_64-unknown-linux-gnu) libcurl/7.36.0 OpenSSL/1.0.2h
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL TLS-SRP

[root@california src]# time ./curl https://curl.haxx.se/download/curl-7.58.0.tar.gz -O --limit-rate 4M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 3788k  100 3788k    0     0  4110k      0 --:--:-- --:--:-- --:--:-- 4113k

real	0m0.936s
user	0m0.027s
sys	0m0.013s

Real download time: real 0m0.936s

The reason for the problem is here

long Curl_pgrsLimitWaitTime(curl_off_t cursize,
                            curl_off_t startsize,
                            curl_off_t limit,
                            struct curltime start,
                            struct curltime now)
{
  ...........

  /* not enough data yet */
  if(size < limit)
    return -1;

  ..........
}

When the download file is less than the limit speed, it cannot be limited

After this code comment, execute the program:

[root@california src]# ./curl -V
curl 7.57.0 (x86_64-pc-linux-gnu) libcurl/7.57.0 OpenSSL/1.0.2h
Release-Date: 2017-11-29
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL TLS-SRP UnixSockets HTTPS-proxy

[root@california src]# time ./curl https://curl.haxx.se/download/curl-7.58.0.tar.gz -O --limit-rate 4M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 3788k  100 3788k    0     0  3788k      0  0:00:01 --:--:--  0:00:01 4052k

real	0m0.950s
user	0m0.026s
sys	0m0.015s

Real download time: real 0m0.950s

operating system

Linux california 4.13.2-1.el7.elrepo.x86_64 #1 SMP Wed Sep 13 18:48:00 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
@bagder

This comment has been minimized.

Show comment
Hide comment
@bagder

bagder Mar 9, 2018

Member

Maybe we should just make it

  /* not enough data yet */
  if(!limit)
    return -1;

What do you think?

Member

bagder commented Mar 9, 2018

Maybe we should just make it

  /* not enough data yet */
  if(!limit)
    return -1;

What do you think?

@liupeidong0620

This comment has been minimized.

Show comment
Hide comment
@liupeidong0620

liupeidong0620 commented Mar 10, 2018

Good idea!

bagder added a commit that referenced this issue Mar 10, 2018

limit-rate: kick in even before "limit" data has been received
... and make sure to avoid integer overflows with really large values.

Reported-by: 刘佩东
Fixes #2371
@bagder

This comment has been minimized.

Show comment
Hide comment
@bagder

bagder Mar 10, 2018

Member

@liupeidong0620 give #2373 a try if you can

Member

bagder commented Mar 10, 2018

@liupeidong0620 give #2373 a try if you can

@bagder bagder closed this in 72a0f62 Mar 11, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.