WCF 限流 Throttling
2012-06-11 15:01
309 查看
WCF 限流 Throttling
限流不是直接的实例管理技术,他允许开发者限制客户端的连接数已经服务器负荷,使用限流技术以后,一旦超出配置的设置值,WCF就会自动的将等待处理的调用放入队列中,然后再依次从队列中取出,如果客户端等待超时,那么客户端会获得一个TimeoutException异常。每个服务类型都可以使用WCf限流技术。WCF限流配置参数
并发会话最大数:针对TCP,IPC等能保持传输层连接的会话的服务绑定的独立客户端最大数,也就是能保持会话的客户端的最大连接数。对于Http等无连接的服务是无效的,默认为10
并发调用最大数:指所有服务实例中读取正在执行的调用总数
并发实例最大数:表示存活的并发上下文总数。默认是无限的。
配置限流
<behaviors>
<serviceBehaviors>
<behavior name = "ThrottledBehavior">
<serviceThrottling
maxConcurrentCalls ="12"
maxConcurrentSessions ="34"
maxConcurrentInstances ="2"
/>
</behavior>
</serviceBehaviors>
</behaviors>
在服务端读取限流参数
ChannelDispatcher dispatcher = OperationContext.Current.Host.ChannelDispatchers[0] as ChannelDispatcher;
ServiceThrottle serviceThrottle = dispatcher.ServiceThrottle;
Trace.WriteLine("MaxConcurrentCalls = "+ serviceThrottle.MaxConcurrentCalls);
Trace.WriteLine("MaxSessions = " + serviceThrottle.MaxConcurrentSessions);
Trace.WriteLine("MaxInstances = " + serviceThrottle.MaxConcurrentInstances);
编程配置限流
宿主进程可以以编程方式配置限流,但是要在打开宿主之前执行
ServiceHost host = new ServiceHost(typeof(MyService));
//Make sure there is no throttle in the config file
ServiceThrottlingBehavior throttle = host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
if(throttle == null)
{
throttle = new ServiceThrottlingBehavior();
throttle.MaxConcurrentCalls = 12;
throttle.MaxConcurrentSessions = 34;
throttle.MaxConcurrentInstances = 2;
host.Description.Behaviors.Add(throttle);
}
host.Open();
绑定中的限流连接
在使用TCP和IPC绑定的时候我们也可以在绑定中为一个特定的终结点配置最大连接数。
<netTcpBinding>
<binding name="TCPThrottle" maxConnections="25"></binding>
</netTcpBinding>
maxConnections的默认值为10,如果绑定限流与服务行为的限流都设置了最大连接值,WCF选择其中较小的一个
相关文章推荐
- WCF 项目应用连载[8] - 绑定、服务、行为 大数据传输与限流 - 下 (ServiceThrottlingAttribute)
- WCF中并发(Concurrency)与限流(Throttling)体系深入解析系列[共7篇]
- 控制并发访问的三道屏障: WCF限流(Throttling)体系探秘[上篇]
- 读Artech的WCF 4.0 -- 基于限流(Throttling)的新特性
- WCF 项目应用连载[8] - 绑定、服务、行为 大数据传输与限流 - 下 (ServiceThrottlingAttribute)
- 控制并发访问的三道屏障: WCF限流(Throttling)体系探秘[下篇]
- 化零为整WCF(12) - 并发和限流(Concurrent和Throttle)
- WCF之并发,吞吐量和限流
- 化零为整WCF(12) - 并发和限流(Concurrent和Throttle)
- 3 ways to do WCF Concurrency Management(Single, Multiple, and Reentrant and How to do with Throttling)
- 快速入门系列--WCF--06并发限流、可靠会话和队列服务
- 限流,WCF配置连接数
- WCF 限流技术
- WCF服务实例模式与并发、限流
- 2009年7月小记(WCF限流行为, 网站性能设置, 序列化的性能, 读取内嵌资源文件, WMI, declarative, XML声明, 相互转换)
- 2009年7月小记(WCF限流行为, 网站性能设置, 序列化的性能, 读取内嵌资源文件, WMI, declarative, XML声明, 相互转换)
- WCF - ServiceThrottlingBehavior
- wcf的并发与限流
- WCF – ServiceThrottlingBehavior
- WCF 项目应用连载[7] - 绑定、服务、行为 大数据传输与限流 - 上