Fork me on GitHub

WCF服务在高负载下可能会变慢

KB2538826 解释了WCF服务在突发的请求下会发生的问题:当您的 WCF 服务接收请求的突发时,默认.Net I/O 完成端口 (IOCP) 线程池可能不扩大需尽快和你 WCF 的响应时间会随之增加。这篇文章《WCF scales up slowly with bursts of work》解释了到底发生了什么。

解决方案是通过另一个线程池执行WCF服务,实施这一解决方案可能会产生少量的开销。 每个WCF服务的性能测试结果会有所不同。

WCF Listener Recommended solution
HTTP Sync Module (Default in 3.x) - used in Integrated Application Pool Switch to the Async handler and then then apply the solution in this article or alternatively use a Private Threadpool (see links following this table)
HTTP Aync Module (Default in 4.x) - used in Integrated Application Pool Apply the code solution in this article
ISAPI - used in Classic Mode Application Pool Apply Private Threadpool (see links following this table)
tcp.Net Apply the code solution in this article

注意:应用此解决方案,当使用WCF侦听器不会阻止传入的线程在等待WCF服务的代码来完成。

如果你按照上面的表在这篇文章中,无法应用的解决方案,使用在MSDN的文章一个专用线程池的例子:
Synchronization Contexts in WCF Juval Lowy将WCF中的同步环境 http://msdn.microsoft.com/zh-cn/magazine/cc163321.aspx

切换同步HTTP处理程序使用异步HTTP处理程序的步骤:

1.WCF调节阈值应高到足以处理预期的突发量在可接受的响应时间。
2. 如果你使用一个.NET CLR默认的线程池,工作人员或IOCP您的WCF服务,你必须确保最低限度的一个数字,你预计并发执行的线程数(价值开始创建线程的限制)。
3. 执行下面的代码在您的服务将执行你的WCF服务的。NET CLR工作线程池。

 

Reusing Cookies in Different WCF Web Services

Less tweaking of your WCF 4.0 apps for high throughput workloads

posted @ 2013-02-09 13:03  张善友  阅读(4325)  评论(2编辑  收藏  举报