成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

WCF限流操作實際設置方式揭秘

開發 開發工具
WCF限流主要指著就是減輕服務負荷,提高資源利用率,幫助開發人員減輕一定負擔。那么,接下來就讓我們一起來看看它的設置方法吧。

WCF中有一種操作可以幫助我們減輕程序開發中產生的大負荷問題,以此提高資源的利用率。那么這一方法就是WCF限流。我們就那天將會通過這里介紹的內容詳細介紹一下WCF限流的實際設置方法。#t#

WCF限流“允許開發者限制客戶端連接數以及服務的負荷。限流可以避免服務的***化,以及分配與使用重要資源的***化。引入限流技術后,一旦超出配置的設置值,WCF就會自動地將等待處理的調用者放入到隊列中,然后依次從隊列中取出。在隊列中等待處理調用時,如果客戶端的調用超時,客戶端就會獲得一個TimeoutException異常。每個服務類型都可以應用限流技術,也就是說,它會影響到服務的所有實例以及服務類型的所有終結點。實現方式是為限流與服務使用的每個通道分發器建立關聯。”

WCF限流由ServiceThrottlingBehavior類定義,包括三個重要的屬性:MaxConcurrentCalls、MaxConcurrentSessions、MaxConcurrentInstances,它們分別的默認值為16,10和Int.MaxValue。

在翻譯過程中,我在查閱MSDN時,發現MaxConcurrentSessions的默認值為64,這讓我感覺很奇怪,莫非作者在這里出現了錯誤。然而經過我仔細地查閱相關資料,發現在WCF的早期版本中,MaxConcurrentSessions的默認值確實為64,但在2006年6月的CTP版本中已經被修改為16。

設置WCF限流值可以通過配置文件,也可以通過編碼方式。前者例如:

 

  1. < system.serviceModel> < services> 
  2. < service name = "MyService" behaviorConfiguration = 
    "ThrottledBehavior"> ... < /service>   
  3. < /services> < behaviors> < serviceBehaviors> 
  4. < behavior name = "ThrottledBehavior"> < serviceThrottling 
    maxConcurrentCalls = "12" maxConcurrentSessions = 
    "34" maxConcurrentInstances = "56" />   
  5. < /behavior> < /serviceBehaviors> < /behaviors> < /system.serviceModel>  

 

WCF并沒有提供關于限流的特性。但實現該特性的方法非常簡單,如下所示:

  1. public class ServiceThrottlingAttribute : Attribute, IServiceBehavior   
  2. {   
  3. private ServiceThrottlingBehavior throttle;   
  4. public ServiceThrottlingAttribute( int maxConcurrentCalls, 
    int maxConcurrentInstances, int maxConcurrentSessions)   
  5. {   
  6. this.throttle = new ServiceThrottlingBehavior();   
  7. throttle.MaxConcurrentCalls = maxConcurrentCalls;   
  8. throttle.MaxConcurrentInstances = maxConcurrentInstances;   
  9. throttle.MaxConcurrentSessions = maxConcurrentSessions; }   
  10. #region IServiceBehavior Members   
  11. void IServiceBehavior.AddBindingParameters(ServiceDescription 
    serviceDescription, ServiceHostBase serviceHostBase, System.Collections.
    ObjectModel.Collection
    < ServiceEndpoint> endpoints, System.
    ServiceModel.Channels.BindingParameterCollection bindingParameters) { }   
  12. void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription 
    serviceDescription, ServiceHostBase serviceHostBase) {   
  13. ServiceThrottlingBehavior currentThrottle = serviceDescription.
    Behaviors.Find
    < ServiceThrottlingBehavior>();   
  14. if (currentThrottle == null) { serviceDescription.Behaviors.Add(this.throttle);   
  15. } }   
  16. void IServiceBehavior.Validate(ServiceDescription serviceDescription, 
    ServiceHostBase serviceHostBase) { } #endregion }   

定義的ServiceThrottlingAttribute特性繼承了Attribute,并實現了IServiceBehavior接口。在特性內,則使用了ServiceThrottlingBehavior類,以設置WCF限流的相關值。如果要配置服務的限流值,就可以應用該特性,例如:

  1. [ServiceThrottling(12, 34, 56)]   
  2. class MyService : IMyContract,IDisposable {   
  3. public void MyMethod( ) {   
  4. ChannelDispatcher dispatcher = OperationContext.
    Current.Host.ChannelDispatchers[0] as ChannelDispatcher;   
  5. ServiceThrottle serviceThrottle = dispatcher.ServiceThrottle;   
  6. Trace.WriteLine("MaxConcurrentCalls = " + serviceThrottle.
    MaxConcurrentCalls);   
  7. Trace.WriteLine("MaxSessions = " + serviceThrottle.
    MaxConcurrentSessions);   
  8. Trace.WriteLine("MaxInstances = " + serviceThrottle.
    MaxConcurrentInstances);   
  9. } }  

則WCF限流的輸出結果為:

MaxConcurrentCalls = 12

MaxSessions = 56

MaxInstances = 34

責任編輯:曹凱 來源: IT168
相關推薦

2009-12-22 15:02:40

WCF限流

2010-02-26 17:44:51

WCF安全參數

2009-11-09 13:04:53

WCF事物處理

2021-04-21 09:55:24

Redis應用限流

2010-03-01 13:06:49

WCF繼承

2010-03-02 10:41:03

IIS托管WCF服務

2010-02-26 14:05:57

WCF通信方式

2009-12-21 14:49:27

2010-02-26 10:56:06

WCF Stream

2010-03-02 17:35:20

WCF服務加載

2009-11-06 12:29:23

2009-11-06 13:23:27

WCF模式

2009-11-06 14:40:34

WCF REST架構

2010-05-12 13:45:25

Mysql 復制設置

2011-12-26 16:33:02

WCF

2010-02-22 13:28:05

WCF異步調用

2010-02-23 10:25:29

2010-02-24 14:05:08

WCF openati

2009-12-22 15:14:33

WCF調用

2010-02-22 14:18:34

WCF服務驗證
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲国产精品福利 | 一二三区视频 | 岛国av一区二区三区 | 人人操日日干 | 精品国产一级 | 超碰电影| 波多野结衣av中文字幕 | 99久久久久久久 | 日韩欧美国产精品一区二区 | 精品视频久久久久久 | 久久精品一区 | 午夜男人免费视频 | 天天操欧美 | av网站免费| 亚洲一区二区三区在线观看免费 | 久久久久久国产精品 | 久久久久成人精品亚洲国产 | 久久精品亚洲成在人线av网址 | 久久久久久久99 | 天天曰夜夜操 | 亚洲区一区二 | 国产成人一区二区三区 | 国产成人精品亚洲日本在线观看 | 91av免费版| 怡红院免费的全部视频 | 国产精品视频一区二区三区不卡 | 久久91av| 久久国产精品免费视频 | 亚洲午夜在线 | 亚洲天堂免费 | 国产精品免费观看 | 欧美午夜精品久久久久免费视 | 亚洲精品视频在线播放 | 午夜不卡福利视频 | 一级毛片色一级 | 大伊人久久 | h视频在线播放 | 久久精品久久精品久久精品 | 日韩欧美在 | 北条麻妃一区二区三区在线观看 | 天天操天天操 |