C# WebClient 上传速度 [英] C# WebClient upload speeds

查看:78
本文介绍了C# WebClient 上传速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能增加 WebClient 异步数据上传的缓冲区大小,因为目前它最大推送 ~320kB/s.

I was wondering if it is possible to increase buffer size on WebClient Async data upload, because currently it pushes ~320kB/s maximum.

我当前的代码:

using (WebClient Client = new WebClient())
{
    byte[] Buffer = File.ReadAllBytes(this.WorkItem.FileLocation);

    Client.UploadProgressChanged += new UploadProgressChangedEventHandler(Client_UploadProgressChanged);
    Client.UploadDataCompleted += new UploadDataCompletedEventHandler(Client_UploadDataCompleted);
    Client.UploadDataAsync(new Uri("-snip-"), Buffer);
}

编辑
连接不是限制因素.(它的 300mbit 连接,网络服务器以 ~30-40mB/s 标记推送内容)

Edit
Connection is not the limiting factor. ( its 300mbit connection, web-servers push content at ~30-40mB/s mark )

推荐答案

如果您想更好地控制数据的缓冲方式,您需要使用 HttpWebRequest 类.使用这个类,您可以选择从 FileStream 读取的读取缓冲区,然后选择写入网络流的数量.执行 4MB 读取和 32KB 写入对于最大化我的网络吞吐量是最佳选择(尽管您必须执行自己的基准测试才能查看哪些缓冲区最适合您的场景).

If you want more control over how the data is buffered you need to use the HttpWebRequest class. With this class you can choose your read buffer reading from a FileStream and then how much you are writing to the network stream. Doing 4MB reads and 32KB writes was optimal for maxing out my network throughput (although you will have to do your own benchmarks to see which buffers work best in your scenario).

这篇关于C# WebClient 上传速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆