I have an application written in .NET 3.5 that uses FTP to upload/download files from a server. The app works fine but there are performance issues:
It takes a lot of time to make connection to the FTP server. The FTP server is on a different network and has Windows 2003 Server (IIS FTP). When multiple files are queued for upload, the change from one file to another creates a new connection using FTPWebRequest and it takes a lot of time (around 8-10 seconds).
Is is possible to re-use the connection? I am not very sure about the KeepAlive property. Which connections are kept alive and reused.
The IIS-FTP on Windows Server 2003 does not support SSL so anyone can easily see the username/password through a packet sniffer such as WireShark. I found that windows Server 2008 supports SSL over FTP in its new version if IIS 7.0.
I basically want to improve the upload/download performance of my application. Any ideas will be appreciated.
** Please note that 3 is not an issue but I would like people to have comments on it
To improve FTP speed on the client-side, increase the parallel (concurrent downloads) or adjust the “maximum simultaneous transfers.” Sometimes FTP servers limit each session to maximum download speed, so this feature will help bypass some limitations defined by the server.
FTP upload and download speed depend mainly on the client's connection to the server. This may be affected by multiple network factors such as hop count and local connectivity. Also, there are other factors which may affect the speed: The number of clients that currently are using the FTP service.
FTP is extremely fast and efficient compared to SMB when transferring large files. It can be difficult when it comes to small files, but overall, the speed of the FTP file transferring protocol is better. The use of short messages in SMB makes it sensible to network latency, which can decrease the speed.
FTP stands for Functional Threshold Power, which is defined as the highest average power you can sustain for approximately an hour, measured in watts.
I have done some experimentation (uploading about 20 files on various sizes) on FtpWebRequest with the following factors
KeepAlive = true/false
ftpRequest.KeepAlive = isKeepAlive;
Connnection Group Name = UserDefined or null
ftpRequest.ConnectionGroupName = "MyGroupName";
Connection Limit = 2 (default) or 4 or 8
ftpRequest.ServicePoint.ConnectionLimit = ConnectionLimit;
Mode = Synchronous or Async
see this example
My results:
Use ConnectionGroupName,KeepAlive=true took (21188.62 msec)
Use ConnectionGroupName,KeepAlive=false took (53449.00 msec)
No ConnectionGroupName,KeepAlive=false took (40335.17 msec)
Use ConnectionGroupName,KeepAlive=true;async=true,connections=2 took (11576.84 msec)
Use ConnectionGroupName,KeepAlive=true;async=true,connections=4 took (10572.56 msec)
Use ConnectionGroupName,KeepAlive=true;async=true,connections=8 took (10598.76 msec)
Conclusions
FtpWebRequest
has been designed to support an internal connection pool. To ensure, the connection pool is used, we must make sure the ConnectionGroupName
is being set.
Setting up a connection is expensive. If we are connecting to the same ftp server using the same credentials, having the keep alive flag set to true will minimize the number of connections setup.
Asynchronous is the recommended way if you have a lot of files to ftp.
The default number of connections is 2. In my environment, a connection limit of 4 will give to me the most overall performance gain. Increasing the number of connections may or may not improve performance. I would recommend that you have the connection limit as a configuration parameter so that you can tune this parameter in your environment.
Hope you would find this useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With