FTP client application encounters slow file download performance issue.

 

Symptom:

The FTP client is a .net client application. It invokes wininet.dll to download files from FTP.

The application downloads ftp files much slower than FTP.exe and other 3rd party ftp client application.

Its speed is <500kb with a 1000M network link.

Troubleshooting:

I collect Network Monitor log to begin the troubleshooting. When the FTP client downloads file, many TCP acknowledge packages are delayed for 10~200ms. The delays of acknowledges accumulate and caused the slow download speed.

And the window size of acknowledge packages is getting smaller and smaller.

This symptom shows that the FTP client application cannot process the data efficiently and requests the FTP server to slow down data transmission.

After checking the code, I find it invokes FtpGetFile like below which is incorrect:

        FtpGetFile(hInternetConnection, filename, filename, false, INTERNET_FLAG_RELOAD, 0, 0);

According to the document, INTERNET_FLAG_RELOAD == 0x80000000 and it should be assigned to the last 2nd parameter. 0x80000000 at the last 3rd parameter means FILE_FLAG_WRITE_THROUGH. This flag can impact disk write performance significantly. See this document https://support.microsoft.com/kb/99794

Solution:

The code is corrected to below one and it is working fantastically now.

        FtpGetFile(hInternetConnection, filename, filename, false, 0, INTERNET_FLAG_RELOAD, 0);

 

Regards,

 

Juntao Zhu