如何提高 FtpWebRequest 的性能?

How to improve the Performance of FtpWebRequest?(如何提高 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:

  1. 连接到 FTP 服务器需要很长时间.FTP 服务器位于不同的网络上,并具有 Windows 2003 Server (IIS FTP).当多个文件排队等待上传时,从一个文件到另一个文件的更改使用 FTPWebRequest 会创建一个新连接,这需要很长时间(大约 8-10 秒).

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

是否可以重复使用连接?我不太确定 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;

模式 = 同步或异步

参见这个例子

我的结果:

  1. 使用 ConnectionGroupName,KeepAlive=true 耗时(21188.62 毫秒)

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

结论

  1. FtpWebRequest 旨在支持内部连接池.为确保使用连接池,我们必须确保设置了 ConnectionGroupName.

  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.

建立连接的成本很高.如果我们使用相同的凭据连接到同一个 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 的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Wait for a single RabbitMQ message with a timeout(等待一条带有超时的 RabbitMQ 消息)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
How do I set a number of retry attempts in RabbitMQ?(如何在 RabbitMQ 中设置重试次数?)
WebClient set headers(WebClient 设置标头)