How to improve the Performance of FtpWebRequest?(如何提高 FtpWebRequest 的性能?)
问题描述
我有一个用 .NET 3.5 编写的应用程序,它使用 FTP 从服务器上传/下载文件.该应用运行良好,但存在性能问题:
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:
连接到 FTP 服务器需要很长时间.FTP 服务器位于不同的网络上,并具有 Windows 2003 Server (IIS FTP).当多个文件排队等待上传时,从一个文件到另一个文件的更改使用 FTPWebRequest 会创建一个新连接,这需要很长时间(大约 8-10 秒).
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).
是否可以重复使用连接?我不太确定 KeepAlive 属性.哪些连接保持活动和重复使用.
Is is possible to re-use the connection? I am not very sure about the KeepAlive property. Which connections are kept alive and reused.
Windows Server 2003 上的 IIS-FTP 不支持 SSL,因此任何人都可以通过 WireShark 等数据包嗅探器轻松查看用户名/密码.如果 IIS 7.0,我发现 windows Server 2008 在其新版本中支持 SSL over FTP.
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.
** 请注意,3 不是问题,但我希望人们对此发表评论
** Please note that 3 is not an issue but I would like people to have comments on it
推荐答案
我在 FtpWebRequest 上做了一些实验(上传大约 20 个不同大小的文件),主要有以下几个因素
I have done some experimentation (uploading about 20 files on various sizes) on FtpWebRequest with the following factors
KeepAlive = 真/假
ftpRequest.KeepAlive = isKeepAlive;
连接组名称 = UserDefined 或 null
Connnection Group Name = UserDefined or null
ftpRequest.ConnectionGroupName = "MyGroupName";
连接限制 = 2(默认)或 4 或 8
Connection Limit = 2 (default) or 4 or 8
ftpRequest.ServicePoint.ConnectionLimit = ConnectionLimit;
模式 = 同步或异步
参见这个例子
我的结果:
使用 ConnectionGroupName,KeepAlive=true 耗时(21188.62 毫秒)
Use ConnectionGroupName,KeepAlive=true took (21188.62 msec)
使用 ConnectionGroupName,KeepAlive=false 耗时(53449.00 毫秒)
Use ConnectionGroupName,KeepAlive=false took (53449.00 msec)
没有 ConnectionGroupName,KeepAlive=false 占用(40335.17 毫秒)
No ConnectionGroupName,KeepAlive=false took (40335.17 msec)
使用 ConnectionGroupName,KeepAlive=true;async=true,connections=2 耗时(11576.84 毫秒)
Use ConnectionGroupName,KeepAlive=true;async=true,connections=2 took (11576.84 msec)
使用 ConnectionGroupName,KeepAlive=true;async=true,connections=4 耗时(10572.56 毫秒)
Use ConnectionGroupName,KeepAlive=true;async=true,connections=4 took (10572.56 msec)
使用 ConnectionGroupName,KeepAlive=true;async=true,connections=8 耗时(10598.76 毫秒)
Use ConnectionGroupName,KeepAlive=true;async=true,connections=8 took (10598.76 msec)
结论
FtpWebRequest旨在支持内部连接池.为确保使用连接池,我们必须确保设置了ConnectionGroupName.
FtpWebRequesthas been designed to support an internal connection pool. To ensure, the connection pool is used, we must make sure theConnectionGroupNameis being set.
建立连接的成本很高.如果我们使用相同的凭据连接到同一个 ftp 服务器,将 keep alive 标志设置为 true 将最大限度地减少连接设置的数量.
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.
如果您有很多要 ftp 的文件,推荐使用异步方式.
Asynchronous is the recommended way if you have a lot of files to ftp.
默认连接数为 2.在我的环境中,连接限制为 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.
这篇关于如何提高 FtpWebRequest 的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何提高 FtpWebRequest 的性能?
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
