WCF NetTcpBinding缓冲与流式性能问题 [英] WCF NetTcpBinding Buffered vs Streamed performance problems

查看:58
本文介绍了WCF NetTcpBinding缓冲与流式性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个WCF服务,该服务应该使用 NetTcpBinding 中的Streamed TransferMode和 System.IO.Stream 对象来转换任何大小的文件.

运行性能测试时,我发现了严重的性能问题.然后,我决定使用Buffered TransferMode对其进行测试,并发现性能快了两倍!

因为我的服务应该传输大文件,所以我只是不能停留在Buffered TransferMode中,因为服务器和客户端的大文件上的内存管理开销在一起.

为什么流式传输模式比缓冲式传输模式慢?我该怎么做才能提高Stremed的性能?

解决方案

您正在流式传输的块有多大?您可能会尝试使用不同的块大小和不同的策略.
另外,考虑使用

您是否阅读过 MS上有关WCF中大数据流的主题的文章?

I wrote a WCF service that should transform any size of files, using the Streamed TransferMode in NetTcpBinding, and System.IO.Stream object.

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!

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.

Why is Streamed TransferMode slower than the Buffered TransferMode? What can i do to make Stremed performance better?

解决方案

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.

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

Keep this in mind:

Did you read MS's article on the topic of large data streaming in WCF?

这篇关于WCF NetTcpBinding缓冲与流式性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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