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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…