Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to improve the Performance of FtpWebRequest?

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:

  1. 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).

  2. Is is possible to re-use the connection? I am not very sure about the KeepAlive property. Which connections are kept alive and reused.

  3. 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

like image 508
A9S6 Avatar asked Jun 19 '09 07:06

A9S6


People also ask

How do I make FTP faster?

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.

Why is my FTP so slow?

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.

Is Samba faster than FTP?

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.

What is FTP performance?

FTP stands for Functional Threshold Power, which is defined as the highest average power you can sustain for approximately an hour, measured in watts.


1 Answers

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:

  1. Use ConnectionGroupName,KeepAlive=true took (21188.62 msec)

  2. Use ConnectionGroupName,KeepAlive=false took (53449.00 msec)

  3. No ConnectionGroupName,KeepAlive=false took (40335.17 msec)

  4. Use ConnectionGroupName,KeepAlive=true;async=true,connections=2 took (11576.84 msec)

  5. Use ConnectionGroupName,KeepAlive=true;async=true,connections=4 took (10572.56 msec)

  6. Use ConnectionGroupName,KeepAlive=true;async=true,connections=8 took (10598.76 msec)

Conclusions

  1. 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.

  2. 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.

  3. Asynchronous is the recommended way if you have a lot of files to ftp.

  4. 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.

like image 141
Syd Avatar answered Oct 05 '22 22:10

Syd