DxC*_*xCK 8 .net c# streaming performance wcf
我编写了一个WCF服务,它应该使用Streamed TransferMode NetTcpBinding和System.IO.Streamobject 来转换任意大小的文件.
在运行性能测试时,我发现了显着的性能问题.然后我决定使用Buffered TransferMode进行测试,看到性能提高了两倍!
因为我的服务应该传输大文件,所以我不能留在Buffered TransferMode,因为服务器和客户端的大文件的内存管理开销在一起.
为什么Streamed TransferMode比Buffered TransferMode慢?我该怎么做才能让Stremed表现更好?
你流的块有多大?您可以尝试不同的块大小和不同的策略.
另外,请考虑使用Asynch IO来填充要传输的缓冲区,或者在传输之后.
我的意思是,如果您的流式算法是串行的,如下所示:
1. Fill a chunk
2. send the chunk
3. get confirmation
4. more chunks? Go to step 1
Run Code Online (Sandbox Code Playgroud)
...那么你有很多不必要的延迟.如果您可以并行填充块并发送块,那么您将能够减少等待.Async IO是一种方法.您将有两个并行的工作流发生.从概念上讲,它可能看起来像这样:
Filling Chunks Sending Chunks
1. call BeginRead 1. get next chunk
2. wait for callback 2. send it
3. more to read? yes -> go to step 1 3. await confirmation
4. done 4. more? go to step 1
Run Code Online (Sandbox Code Playgroud)
但是使用Async IO,这些实际上可能是由同一个线程驱动的.
记住这一点:
替代文字http://i45.tinypic.com/t82r92.jpg
您是否阅读过MS关于WCF中大数据流主题的文章?