1

I use TIdHTTP to download updates of my application. The install file is about 80 mb.

It works, but I noticed that somehow, the download speed is way slower than the same link downloaded directly from Google Chrome.

Why does this happen? Is there any setup I should do on TIdHTTP to speed up the download?

Nothing fancy on my code, I just use the Get() method like this:

idh := TIdHTTP.Create(nil);
ssl := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
ssl.SSLOptions.Method := sslvSSLv23;
ssl.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
f := TFileStream.Create(localFileName, fmCreate);
idh.Get(remoteFile, f);
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
delphirules
  • 6,443
  • 17
  • 59
  • 108
  • 1
    Maybe in Chrome the "Parallel downloading" (experimental) feature is enabled? – mjn Dec 03 '22 at 12:52
  • Chrome may open up to six simultaneous persistent connections per server/proxy (https://stackoverflow.com/a/985704/80901), which iiuc means downloads of a file may be up to six times faster. (if Parallel downloading is enabled) – mjn Dec 03 '22 at 12:59
  • You could try to use `URLDownloadToFile` function to download the file from the `UrlMon` library. – Codex Dec 06 '22 at 13:42

1 Answers1

1

With TIdHTTP you may implement parallel downloading by launching two or more HTTP GET Requests in different threads, which each download a specific part of the resource. This however only will increase download speed if the system has enough CPU resources to execute the threads on different "cores".

See https://stackoverflow.com/a/9678441/80901 for some related information

mjn
  • 36,362
  • 28
  • 176
  • 378
  • 1
    This doesn't make sense to me. Surely the bottleneck in downloading a file from the Internet isn't CPU? – Andreas Rejbrand Dec 03 '22 at 13:27
  • @AndreasRejbrand I don't say it is, I was only suggesting to try parallel download to reduce the perceived download time. – mjn Dec 03 '22 at 13:31
  • 4
    There is a lot of overhead involved behind the scenes to make such a "simple" code work. There is the DNS lookup, the TCP handshake, the TLS handshake, network latency, and filesystem I/O all play part in how long the operation takes. For instance, try downloading by IP instead of hostname, and downloading to a TMemoryStream or TBufferedFileStream instead of a vanilla TFileStream, and see how much faster it may be. – Remy Lebeau Dec 03 '22 at 17:35
  • @RemyLebeau 100% agreed and thanks for the additional suggestions. My proposal was not meant as a general solution, but may be working for medium size files and servers which support range requests. – mjn Dec 04 '22 at 18:58