WCF Rest服务 - 流式下载非常慢。 [英] WCF Rest service - streaming download is VERY slow.
问题描述
你好WCF好友,我有一个大问题。
我正在尝试使用REST WCF下载文件,但看起来,例如,16MB文件花了我56秒,但在常规下载(相同的来源 - 来自我们的网站) - 需要8秒。
在客户端,我正在阅读这样的块:
// 初始化
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(test.FullURL);
request.Method = test.Method.ToString();
if (test.Method!= TestMethod.GET)
{
request.ContentType = application / json;
使用(Stream requestStream = request.GetRequestStream())
{
byte [] inputStringBytes = Encoding.UTF8.GetBytes(test.InputData);
requestStream.Write(inputStringBytes, 0 ,inputStringBytes.Length);
}
}
使用( var response = request.GetResponse ())
{
使用(Stream responseStream = response.GetResponseStream())
{
System.Diagnostics。秒表watch = new System.Diagnostics.Stopwatch();
char [] btArray = new char [ 5242880 ];
watch.Start();
StreamReader rdr = new StreamReader(responseStream,Encoding.UTF8);
int idx = 0 ;
int length = 0 ;
while (!rdr.EndOfStream)
{
idx = rdr.ReadBlock(btArray, 0 , 5242880 );
// _ result.actual + = new string(btArray,0,idx);
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
}
}
我使用的是5MB块,文件是16MB,因为我说。
配置是基本的:
< service behaviorConfiguration = httpBehavior 名称 = 名称 >
< endpoint 地址 = binding = webHttpBinding bindingConfiguration = webHttpBindingConfig behaviorConfiguration = web 合同 = IService / >
< / service >
...
...
< webHttpBinding >
< binding name = webHttpBindingConfig transferMode < span class =code-keyword> = 流式 maxBufferSize = 52428800 maxReceivedMessageSize = 52428800 >
< readerQuotas maxDepth = 32 maxStringContentLength = < span class =code-keyword> 52428800 maxArrayLength = 52428800 maxBytesPerRead = 52428800 maxNameTableCharCount = 52428800 / >
< < span class =code-leadattribute> security mode = 运输 >
< transport clientCredentialType = 无 proxyCredentialType = 无 领域 = / >
< / security >
< / binding >
< / webHttpBinding >
(我甚至在所有配置中都做了很多数字,看看是否有帮助 - 没什么)。
我错过了什么吗?
谢谢。
检查这些
WCF优化和服务@高速 [ ^ ]
提升绩效的快速方法ASP.NET,WCF和Desktop Cl的可伸缩性客户 [ ^ ]
性能调优WCF服务,第1部分 [ ^ ]
性能调优WCF服务,第2部分 [ ^ ]
优化WCF Web服务性能 [ ^ ]
创建高性能WCF服务 [ ^ ]
WCF性能优化技巧 [ ^ ]
WCF优化和调整 [ ^ ]
WCF性能调整 [ ^ ]
Hello WCF Friends,i have a major problem.
i'm trying to download files using REST WCF, but it appears that, for example, 16MB file takes me 56 seconds, but in regular download (same source - from a website we have) - it takes 8 seconds.
In the client side, i'm reading the chunks like that:
// Initialize
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(test.FullURL);
request.Method = test.Method.ToString();
if (test.Method != TestMethod.GET)
{
request.ContentType = "application/json";
using (Stream requestStream = request.GetRequestStream())
{
byte[] inputStringBytes = Encoding.UTF8.GetBytes(test.InputData);
requestStream.Write(inputStringBytes, 0, inputStringBytes.Length);
}
}
using (var response = request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
char[] btArray = new char[5242880];
watch.Start();
StreamReader rdr = new StreamReader(responseStream, Encoding.UTF8);
int idx = 0;
int length = 0;
while (!rdr.EndOfStream)
{
idx = rdr.ReadBlock(btArray, 0, 5242880);
//_result.actual += new string(btArray, 0, idx);
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
}
}
I'm using 5MB chunks, the file is 16MB as i said.
the configuration is basiclly:
<service behaviorConfiguration="httpBehavior" name="Name">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig" behaviorConfiguration="web" contract="IService" />
</service>
...
...
<webHttpBinding>
<binding name="webHttpBindingConfig" transferMode="Streamed" maxBufferSize="52428800" maxReceivedMessageSize="52428800">
<readerQuotas maxDepth="32" maxStringContentLength="52428800" maxArrayLength="52428800" maxBytesPerRead="52428800" maxNameTableCharCount="52428800"/>
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
</security>
</binding>
</webHttpBinding>
(i even did large numbers in all configurations to see if that helps - nothing).
Am i missing something?
Thanks.
Check these
WCF Optimization and Service @ High Speed[^]
Quick Ways to Boost Performance and Scalability of ASP.NET, WCF and Desktop Clients[^]
Performance Tuning WCF Services, Part 1[^]
Performance Tuning WCF Services, Part 2[^]
Optimizing WCF Web Service Performance[^]
Creating high performance WCF services[^]
WCF Performance Optimization Tips[^]
WCF Optimization and Tuning[^]
WCF Performance Tuning[^]
这篇关于WCF Rest服务 - 流式下载非常慢。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!