C# WebClient upload speeds

谁说我不能喝 提交于 2019-12-24 09:22:35

问题


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

My current code:

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);
}

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


回答1:


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



来源:https://stackoverflow.com/questions/11719804/c-sharp-webclient-upload-speeds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!