简体   繁体   English

WCF NetTcpBinding缓冲与流式处理性能问题

[英]WCF NetTcpBinding Buffered vs Streamed performance problems

I wrote a WCF service that should transform any size of files, using the Streamed TransferMode in NetTcpBinding , and System.IO.Stream object. 我编写了一个WCF服务,它应该使用NetTcpBinding的Streamed TransferMode和System.IO.Stream对象转换任意大小的文件。

When running performance test, i found significant performance problem. 运行性能测试时,我发现了很大的性能问题。 Then I decided to test it with Buffered TransferMode and saw that performance is two times faster! 然后我决定使用Buffered TransferMode进行测试,看到性能提高了两倍!

Because my service should transfer big files, i just can't stay in Buffered TransferMode because of memory management overhead on big files at the server and client side together. 因为我的服务应该传输大文件,所以我不能留在Buffered TransferMode,因为服务器和客户端的大文件的内存管理开销在一起。

Why is Streamed TransferMode slower than the Buffered TransferMode? 为什么Streamed TransferMode比Buffered TransferMode慢? What can i do to make Stremed performance better? 我该怎么做才能让Stremed表现更好?

How big are the chunks you are streaming? 你流的块有多大? You might experiment with varying chunk sizes, and varying strategies. 您可以尝试不同的块大小和不同的策略。
Also, consider using Asynch IO to fill the buffers to be transferred, or after transfer. 另外,请考虑使用Asynch IO来填充要传输的缓冲区,或者在传输之后。

What I mean is, if your streaming algorithm is serial, like so: 我的意思是,如果您的流式算法是串行的,如下所示:

1. Fill a chunk
2. send the chunk
3. get confirmation
4. more chunks?  Go to step 1

...then you have a lot of unnecessary delay. ...那么你有很多不必要的延迟。 If you can fill chunks and send chunks in parallel, then you'll be able to reduce waiting. 如果您可以并行填充块并发送块,那么您将能够减少等待。 Async IO is one way to do that. Async IO是一种方法。 You would have two parallel workstreams happening. 您将有两个并行的工作流发生。 Conceptually, it might look like this: 从概念上讲,它可能看起来像这样:

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

But using Async IO, these could actually be driven by the same thread. 但是使用Async IO,这些实际上可能是由同一个线程驱动的。

Keep this in mind: 记住这一点:

替代文字

Did you read MS's article on the topic of large data streaming in WCF? 您是否阅读过MS关于WCF中大数据流主题的文章?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM