江苏快三开奖结果

Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

LUMANMAN,CHANGXIUYUAN,WOMENBUNENGMEIYOUQIAN

兩種高性能I/O設計模式(Reactor/Proactor)的比較

原文出處: Alex Libman   譯文出處:潘孫友



ZONGSHU

ZHEPIANWENZHANGTANTAOBINGBIJIAOLIANGZHONGYONGYUTCPFUWUQIDEGAOXINGNENGSHEJIMOSHI。 CHULEJIESHAOXIANYOUDEJIEJUEFANGAN,HUANTICHULEYIZHONGGENGJUSHENSUOXING,ZHIXUYAOWEIHUYIFENDAIMABINGQIEKUAPINGTAIDEJIEJUEFANGAN(HANDAIMASHILI),YIJIQIZAIBUTONGPINGTAISHANGDEWEIDIAO。 CIWENHUANBIJIAOLEjava、c#、c++DUIGEZIXIANYOUYIJITIDAODEJIEJUEFANGANDESHIXIANXINGNENG。

XITONGI/O KEFENWEIZUSAIXING, FEIZUSAITONGBUXINGYIJIFEIZUSAIYIBUXING[、]。 ZUSAIXINGI/OYIWEIZHUKONGZHIQUANZHIDAODIAOYONGCAOZUOJIESHULECAIHUIHUIDAODIAOYONGZHESHOULI。 JIEGUODIAOYONGZHEBEIZUSAILE, ZHEDUANSHIJIANLEZUOBULERENHEQITASHIQING。 GENGYUMENDESHI,ZAIDENGDAIIOJIEGUODESHIJIANLI,DIAOYONGZHESUOZAIXIANCHENGCISHIWUFATENGCHUSHOULAIQUXIANGYINGQITADEQINGQIU,ZHEZHENSHITAILANGFEIZIYUANLE。NAread()CAOZUOLAISHUOBA, DIAOYONGCIHANSHUDEDAIMAHUIYIZHIJIANGZAICICHUZHIZHITASUODUDEsocketHUANCUNZHONGYOUSHUJUDAOLAI。

江苏快三开奖结果XIANGBIZHIXIA,FEIZUSAITONGBUSHIHUILIJIFANHUIKONGZHIQUANGEIDIAOYONGZHEDE。DIAOYONGZHEBUXUYAODENGDENG,TACONGDIAOYONGDEHANSHUHUOQULIANGZHONGJIEGUO:YAOMECICIDIAOYONGCHENGGONGJINXINGLE;YAOMEXITONGFANHUICUOWUBIAOSHIGAOSUDIAOYONGZHEDANGQIANZIYUANBUKEYONG,NIZAIDENGDENGHUOZHEZAISHIDUKANBA。BIRUread()CAOZUO, RUGUODANGQIANsocketWUSHUJUKEDU,ZELIJIFANHUIEWOULBLOCK/EAGAIN,GAOSUDIAOYONGread()ZHE”SHUJUHUANMEIZHUNBEIHAO,NISHAOHOUZAISHI”。

ZAIFEIZUSAIYIBUDIAOYONGZHONG,SHAOYOUBUTONG。DIAOYONGHANSHUZAILIJIFANHUISHI,HUANGAOSUDIAOYONGZHE,ZHECIQINGQIUYIJINGKAISHILE。XITONGHUISHIYONGLINGWAIDEZIYUANHUOZHEXIANCHENGLAIWANCHENGZHECIDIAOYONGCAOZUO,BINGZAIWANCHENGDESHIHOUZHIHUIDIAOYONGZHE(BIRUTONGGUOHUIDIAOHANSHU)。NAWindowsDEReadFile()HUOZHEPOSIXDEaio_read()LAISHUO,DIAOYONGTAZHIHOU,HANSHULIJIFANHUI,CAOZUOXITONGZAIHOUTAITONGSHIKAISHIDUCAOZUO。

ZAIYISHANGSANZHONGIOXINGSHIZHONG,FEIZUSAIYIBUSHIXINGNENGZUIGAO、SHENSUOXINGZUIHAODE。

江苏快三开奖结果ZHEPIANWENZHANGTANTAOBUTONGDEI/OLIYONGJIZHIBINGTIGONGYIZHONGKUAPINGTAIDESHEJIMOSHI(JIEJUEFANGAN)。 XIWANGCIWENKEYIGEIYUTCPGAOXINGNENGFUWUQIKAIFAZHEYIXIEBANGZHU,XUANZEZUIJIADESHEJIFANGAN。XIAMIANWOMENHUIBIJIAO Java、C#、 C++GEZIDUITANTAOFANGANDESHIXIANYIJIXINGNENG。 WOMENZAIWENZHANGDEHOUMIANJIUBUZAITIJIZUSAISHIDEFANGANLE,YINWEIZUSAISHII/OSHIZAISHIQUESHAOKESHENSUOXING,XINGNENGYEDABUDAOGAOXINGNENGFUWUQIDEYAOQIU。

LIANGZHONGIODUOLUFUYONGFANGAN:Reactor and Proactor

江苏快三开奖结果YIBANQINGKUANGXIA,I/O FUYONGJIZHIXUYAOSHIJIANFENXIANGQI(event demultiplexor [、])。 SHIJIANFENXIANGQIDEZUOYONG,JIJIANGNEIXIEDUXIESHIJIANYUANFENFAGEIGEDUXIESHIJIANDECHULIZHE,JIUXIANGSONGKUAIDIDEZAILOUXIAHAN: SHUIDESHENMEDONGXISONGLE, KUAILAINABA。KAIFARENYUANZAIKAISHIDESHIHOUXUYAOZAIFENXIANGQINEILIZHUCEGANXINGQUDESHIJIAN,BINGTIGONGXIANGYINGDECHULIZHE(event handlers),HUOZHESHIHUIDIAOHANSHU; SHIJIANFENXIANGQIZAISHIDANGDESHIHOUHUIJIANGQINGQIUDESHIJIANFENFAGEIZHEXIEhandlerHUOZHEHUIDIAOHANSHU。

SHEJIDAOSHIJIANFENXIANGQIDELIANGZHONGMOSHICHENGWEI:Reactor and Proactor []。 ReactorMOSHISHIJIYUTONGBUI/ODE,ERProactorMOSHISHIHEYIBUI/OXIANGGUANDE。 ZAIReactorMOSHIZHONG,SHIJIANFENLIZHEDENGDAIMOUGESHIJIANHUOZHEKEYINGYONGHUOGECAOZUODEZHUANGTAIFASHENG(BIRUWENJIANMIAOSHUFUKEDUXIE,HUOZHESHIsocketKEDUXIE),SHIJIANFENLIZHEJIUBAZHEGESHIJIANCHUANGEISHIXIANZHUCEDESHIJIANCHULIHANSHUHUOZHEHUIDIAOHANSHU,YOUHOUZHELAIZUOSHIJIDEDUXIECAOZUO。

ERZAIProactorMOSHIZHONG,SHIJIANCHULIZHE(HUOZHEDAIYOUSHIJIANFENLIZHEFAQI)ZHIJIEFAQIYIGEYIBUDUXIECAOZUO(XIANGDANGYUQINGQIU),ERSHIJIDEGONGZUOSHIYOUCAOZUOXITONGLAIWANCHENGDE。FAQISHI,XUYAOTIGONGDECANSHUBAOKUOYONGYUCUNFANGDUDAOSHUJUDEHUANCUNQU,DUDESHUJUDAXIAO,HUOZHEYONGYUCUNFANGWAIFASHUJUDEHUANCUNQU,YIJIZHEGEQINGQIUWANHOUDEHUIDIAOHANSHUDENGXINXI。SHIJIANFENLIZHEDEZHILEZHEGEQINGQIU,TAMOMODENGDAIZHEGEQINGQIUDEWANCHENG,RANHOUZHUANFAWANCHENGSHIJIANGEIXIANGYINGDESHIJIANCHULIZHEHUOZHEHUIDIAO。JULILAISHUO,ZAIWindowsSHANGSHIJIANCHULIZHETOUDILEYIGEYIBUIOCAOZUO(CHENGYOUoverlappedDEJISHU),SHIJIANFENLIZHEDENGIOCompletionSHIJIANWANCHENG[]。 ZHEZHONGYIBUMOSHIDEDIANXINGSHIXIANSHIJIYUCAOZUOXITONGDICENGYIBUAPIDE,SUOYIWOMENKECHENGZHIWEI“XITONGJIBIE”DEHUOZHE“ZHENZHENGYIYISHANG”DEYIBU,YINWEIJUTIDEDUXIESHIYOUCAOZUOXITONGDAILAODE。

JULINGWAIGELIZILAIGENGHAODILIJIEReactorYUProactorLIANGZHONGMOSHIDEQUBIE。ZHELIWOMENZHIGUANZHUreadCAOZUO,YINWEIwriteCAOZUOYESHICHABUDUODE。XIAMIANSHIReactorDEZUOFA:

  • 某個事件處理者宣稱它對某個socket上的讀事件很感興趣;
  • 事件分離者等著這個事件的發生;
  • 當事件發生了,事件分離器被喚醒,這負責通知先前那個事件處理者;
  • 事件處理者收到消息,于是去那個socket上讀數據了。 如果需要,它再次宣稱對這個socket上的讀事件感興趣,一直重復上面的步驟;

XIAMIANZAILAIKANKANZHENZHENGYIYIDEYIBUMOSHIProactorSHIRUHEZUODE:

  • 事件處理者直接投遞發一個寫操作(當然,操作系統必須支持這個異步操作)。 這個時候,事件處理者根本不關心讀事件,它只管發這么個請求,它魂牽夢縈的是這個寫操作的完成事件。這個處理者很拽,發個命令就不管具體的事情了,只等著別人(系統)幫他搞定的時候給他回個話。
  • 事件分離者等著這個讀事件的完成(比較下與Reactor的不同);
  • 當事件分離者默默等待完成事情到來的同時,操作系統已經在一邊開始干活了,它從目標讀取數據,放入用戶提供的緩存區中,最后通知事件分離者,這個事情我搞完了;
  • 事件分享者通知之前的事件處理者: 你吩咐的事情搞定了;
  • 事件處理者這時會發現想要讀的數據已經乖乖地放在他提供的緩存區中,想怎么處理都行了。如果有需要,事件處理者還像之前一樣發起另外一個寫操作,和上面的幾個步驟一樣。

XIANXINGZUOFA

KAIYUANC++KAIFAKUANGJIA ACE[、](Douglas Schmidt, et al.KAIFA) TIGONGLEDALIANGPINGTAIDULIDEDICENGBINGFAZHICHILEI(XIANCHENG、HUCHILIANGDENG)。 TONGSHIZAIGENGGAOYICENGTAYETIGONGLEDULIDEJIZUC++LEI,YONGYUSHIXIANReactorJIProactorMOSHI。 JINGUANTAMENDOUSHIPINGTAIDULIDEDANYUAN,DANTAMENDOUTIGONGLEBUTONGDEJIEKOU。

ACE ProactorZAIMS-WindowsSHANGWULUNSHIXINGNENGHUANZAIJIANZHUANGXINGDOUGENGSHENGYICHOU,ZHEZHUYAOSHIYOUYUWindowsTIGONGLEYIXILIEGAOXIAODEDICENGYIBUAPI。 [、]。

江苏快三开奖结果(ZHEDUANKENENGGUOSHILEDIANBA) BUXINGDESHI,BINGBUSHISUOYOUCAOZUOXITONGDOUWEIDICENGYIBUTIGONGJIANZHUANGDEZHICHI。JULILAISHUO, XUDUOUnixXITONGJIUYOUMAFAN。YINCI, ACE ReactorKENENGSHIUnixXITONGSHANGGENGHESHIDEJIEJUEFANGAN。 ZHENGYINWEIXITONGDICENGDEZHICHILIDUBUYI,WEILEZAIGEXITONGSHANGYOUGENGHAODEXINGNENG,KAIFAZHEBUDEBUWEIHUDULIDEHAOJIFENDAIMA: WEIWindowsZHUNBEIDEACE ProactorYIJIWEIUnixXILIETIGONGDEACE Reactor。

JIUXIANGWOMENTIDAOGUODE,ZHENZHENGDEYIBUMOSHIXUYAOCAOZUOXITONGJIBIEDEZHICHI。YOUYUSHIJIANCHULIZHEJICAOZUOXITONGJIAOHUDECHAYI,WEIReactorHEProactorSHEJIYIZHONGTONGYONGTONGYIDEWAIBUJIEKOUSHIFEICHANGKUNNANDE。ZHEYESHISHEJITONGXINGKAIFAKUANGJIADENANDIANSUOZAI。

GENGHAODEJIEJUEFANGAN

江苏快三开奖结果ZAIWENZHANGZHEYIDUANSHI,WOMENJIANGCHANGSHITIGONGYIZHONGRONGHELEProactorHEReactorLIANGZHONGMOSHIDEJIEJUEFANGAN。 WEILEYANSHIZHEGEFANGAN,WOMENJIANGReactorSHAOZUODIAOZHENG,MONICHENGYIBUDEProactorMOXING(ZHUYAOSHIZAISHIJIANFENLIQILIWANCHENGBENGAISHIJIANCHULIZHEZUODESHIJIDUXIEGONGZUO,WOMENCHENGZHEZHONGFANGFAWEI”MONIYIBU“)。 XIAMIANDESHILIKEYIKANKANreadCAOZUOSHIRUHEWANCHENGDE:

  • 事件處理者宣稱對讀事件感興趣,并提供了用于存儲結果的緩存區、讀數據長度等參數;
  • 調試者等待(比如通過select());
  • 當有事件到來(即可讀),調試者被喚醒, 調試者去執行非阻塞的讀操作(前面事件處理者已經給了足夠的信息了)。讀完后,它去通知事件處理者。
  • 事件處理者這時被知會讀操作已完成,它擁有完整的原先想要獲取的數據了。

江苏快三开奖结果WOMENKANDAO,TONGGUOWEIFENLIZHE(YEJIUSHANGMIANDEDIAOSHIZHE)TIANJIAYIXIEGONGNENG,KEYIRANGReactorMOSHIZHUANHUANWEIProactorMOSHI。SUOYOUZHEXIEBEIZHIXINGDECAOZUO,QISHISHIHEReactorMOXINGYINGYONGSHIWANQUANYIZHIDE。WOMENZHISHIBAGONGZUODASANFENPEIGEIBUTONGDEJIAOSEQUWANCHENGERYI。ZHEYANGBINGBUHUIYOUEWAIDEKAIXIAO,YEBUHUIYOUXINGNENGSHANGDEDESUNSHI,WOMENKEYIZAIZIXIKANKANXIAMIANDELIANGGEGUOCHENG,TAMENSHIJISHANGWANCHENGLEYIYANGDESHIQING:

江苏快三开奖结果BIAOZHUNDEJINGDIANDE ReactorMOSHI:

  • 步驟 1) 等待事件 (Reactor 的工作)
  • 步驟 2) 發”已經可讀”事件發給事先注冊的事件處理者或者回調 ( Reactor 要做的)
  • 步驟 3) 讀數據 (用戶代碼要做的)
  • 步驟 4) 處理數據 (用戶代碼要做的)

MONIDEProactorMOSHI:

  • 步驟 1) 等待事件 (Proactor 的工作)
  • 步驟 2) 讀數據(看,這里變成成了讓 Proactor 做這個事情)
  • 步驟 3) 把數據已經準備好的消息給用戶處理函數,即事件處理者(Proactor 要做的)
  • 步驟 4) 處理數據 (用戶代碼要做的)

ZAIMEIYOUDICENGYIBUI/O APIZHICHIDECAOZUOXITONG,ZHEZHONGFANGFAKEYIBANGWOMENYINZANGDIAOsocketJIEKOUDECHAYI(WULUNSHIXINGNENGHUANSHIQITA), TIGONGYIGEWANQUANKEYONGDETONGYI“YIBUJIEKOU”。ZHEYANGWOMENJIUKEYIKAIFAZHENZHENGPINGTAIDULIDETONGYONGJIEKOULE。

TProactor

江苏快三开奖结果WOMENTICHUDETProactorFANGANYIJINGYOUTerabitP/L []GONGSISHIXIANLE。 TAYOULIANGZHONGSHIXIAN: C++DEHEJavaDE。C++BANBENSHIYONGLEACEPINGTAIDULIDEDICENGYUANJIAN,ZUIZHONGZAISUOYOUCAOZUOXITONGSHANGTIGONGLETONGYIDEYIBUJIEKOU。

TProactorZHONGZUIZHONGYAODEZUJIANYAOSHUEngineHEWaitStrategyLE。 EngineYONGYUWEIHUYIBUCAOZUODESHENGMINGZHOUQI;ERWaitStrategyYONGYUGUANLIBINGFACELVE。 WaitStrategyHEEngineYIBANSHICHENGDUICHUXIANDE, LIANGZHEJIANTIGONGLELIANGHAODEPIPEIJIEKOU。

EnginesHEDENGDAICELVEBEISHEJICHENGGAODUKEZUHEDE(WANZHENGDESHIXIANLIEBIAOQINGCANZHAOFULU1)。TProactorSHIGAODUKEPEIZHIDEFANGAN,TONGGUOSHIYONGYIBUNEIHEAPIHETONGBUUnix API(select(), poll(), /dev/poll (Solaris 5.8+), port_get(Solaris 5.10),RealTime (RT) signals (Linux 2.4+), epoll (Linux 2.6), k-queue (FreeBSD) ),TANEIBUSHIXIANLESANZHONGYINQING(POSIX AIO, SUN AIO and Emulated AIO)BINGYINZANGLELIULEIDENGDAICELVE。TProactorSHIXIANLEHEBIAOZHUNDE ACE ProactorYIYANGDEJIEKOU。ZHEYANGYILAI,WEIBUTONGPINGTAITIGONGTONGYONGTONGYIDEZHIYOUYIFENDAIMADEKUAPINGTAIJIEJUEFANGANCHENGWEIKENENG。

江苏快三开奖结果EnginesHEWaitStrategiesKEYIXIANGLEGAOJIMUYIYANGZIYOUDIZUHE,KAIFAZHEKEYIZAIYUNXINGSHITONGGUOPEIZHICANSHULAIXUANZEHESHIDENEIBUJIZHI(YINQINGHEDENGDAICELVE)。KEYIGENJUXUQIUSHEDINGPEIZHI,BIRULIANJIESHU,XITONGSHENSUOXING,YIJIYUNXINGDECAOZUOXITONGDENG。RUGUOXITONGZHICHIXIANGYINGDEYIBUDICENGAPI,KAIFARENYUANKEYIXUANZEZHENZHENGDEYIBUCELVE,FOUZEYONGHUYEKEYIXUANZESHIYONGMONICHULAIDEYIBUMOSHI。SUOYOUZHEYIQIECELVESHANGDESHIXIANXIJIEDOUBUTAIXUYAOGUANZHU,WOMENKANDAODESHIYIGEKEYONGDEYIBUMOXING。

JULILAISHUO,DUIYUYUNXINGZAISun SolarisSHANGDEHTTPFUWUQI,RUGUOXUYAOZHICHIDALIANGDELIANJIESHU,/dev/pollHUOZHEport_get()ZHILEIDEYINQINGSHIBIJIAOHESHIDEXUANZE;RUGUOXUYAOGAOTUNTULIANG,NEISHIYONGJIBENselect()DEYINQINGHUIGENGHAO。YOUYUBUTONGXUANZECELVENEIZAISUANFADEWENTI,XIANGZHEYANGDEDANXINGXUANZESHIBIAOZHUNACE Reactor/ProactorMOSHISUOWUFATIGONGDE(JIANFULU2)。

ZAIXINGNENGFANGMIAN,WOMENDECESHIXIANSHI,MONIYIBUMOSHIBINGWEIZAOCHENGRENHEKAIXIAO,MEIYOUBIANMAN,FANDAOSHIXINGNENGYOUSUOTISHENG。GENJUWOMENDECESHIJIEGUO,TProactorXIANGJIAOBIAOQIANDEACE ReactorZAIUnix/LinuxXITONGSHANGYOUDAYUE10-35%XINGNENGTISHENG,ERZAIWindowsSHANGCHABUDUO(CESHILETUNTULIANGJIXIANGYINGSHIJIAN)。

江苏快三开奖结果XINGNENGBIJIAO (JAVA / C++ / C#).

CHULEC++,WOMENYEZAIJavaZHONGSHIXIANLETProactor。 JDK1.4ZHONG, JavaJINTIGONGLETONGBUFANGFA, XIANGCZHONGDEselect() [、]。 Java TProactorJIYUJavaDEFEIZUSAIGONGNENG(java.nioBAO),LEISIYUC++DETProactorSHIYONGLEselect()YINQING。

江苏快三开奖结果TU1、2XIANSHILEYI bits/secWEIDANWEIDECHUANSHUSUDUYIJIXIANGYINGDELIANJIESHU。ZHEXIETUBIJIAOLEYIXIASANZHONGFANGSHISHIXIANDEechoFUWUQI:BIAOZHUNACE ReactorSHIXIAN(JIYURedHat Linux9.0)、TProactor C++/JavaSHIXIAN(Microsoft WindowsPINGTAIJIRedHat v9.0), YIJIC#SHIXIAN。CESHIDESHIHOU,SANZHONGFUWUQISHIYONGXIANGTONGDEKEHUDUANFENGKUANGDILIANJIE,BUJIANDUANDIFASONGGUDINGDAXIAODESHUJUBAO。

這幾組測試是在相同的硬件上做的,在不同硬件上做的相對結果對比也是類似。



圖 1. Windows XP/P4 2.6GHz HyperThreading/512 MB RAM.




圖 2. Linux RedHat 2.4.20-smp/P4 2.6GHz HyperThreading/512 MB RAM.


YONGHUDAIMASHILI

下面是TProactor Java實現的echo服務器代碼框架。總的來說,開發者只需要實現兩個接口:一是OpRead,提供存放讀結果的緩存;二是OpWrite,提供存儲待寫數據的緩存區。同時,開發者需要通過回調onReadComplated()和onWriteCompleted()實現協議相關的業務代碼。這些回調會在合適的時候被調用。


 1 class EchoServerProtocol implements AsynchHandler
 2 {
 3  
 4   AsynchChannel achannel = null;
 5  
 6   EchoServerProtocol( Demultiplexor m,  SelectableChannel channel ) 
 7   throws Exception
 8   {
 9     this.achannel = new AsynchChannel( m, this, channel );
10   }
11  
12   public void start() throws Exception
13   {
14     
15 // called after construction
16     System.out.println( Thread.currentThread().getName() + 
17     ": EchoServer protocol started" );
18     achannel.read( buffer);
19   }
20  
21   public void onReadCompleted( OpRead opRead ) throws Exception
22   {
23     if ( opRead.getError() != null )
24     {
25       
26 // handle error, do clean-up if needed
27       System.out.println( "EchoServer::readCompleted: " + 
28       opRead.getError().toString());
29       achannel.close();
30       return;
31     }
32  
33     if ( opRead.getBytesCompleted () <= 0)
34     {
35       System.out.println("EchoServer::readCompleted: Peer closed "
36        + opRead.getBytesCompleted();
37       achannel.close();
38       return;
39     }
40  
41     ByteBuffer buffer = opRead.getBuffer();
42  
43     achannel.write(buffer);
44   }
45  
46   public void onWriteCompleted(OpWrite opWrite) 
47   throws Exception
48   {
49     
50 // logically similar to onReadCompleted
51     
52   }
53 }


江苏快三开奖结果IO多路復用模型有兩種Proactor與Reactor,兩者的區別主要在于IO是同步還是異步。

江苏快三开奖结果ProactorBIReactorGENGGAOXIAO。

XIAMIANSHILIANGZHONGMOSHIDEQINGQIUCHULIGUOCHENG:

處理過程

Proactor

  1. client創建要進行的操作,并注冊操作完成時的回調處理函數
  2. 操作(opration)交由操作系統底層進行處理
  3. 處理完成后底層將操作結果和回調函數傳給Proactor調度器
  4. Proactor調度器進行分發事件,調用具體的回調處理函數。

Reactor

  1. 對事件進行注冊處理函數。
  2. client的請求觸發底層的事件。
  3. Reactor調度器檢查事件發生,執行注冊的處理函數。

區別和聯系

區別

江苏快三开奖结果ZAISHIXIANZHONG,ProactorSHIFACHUYIBUIOQINGQIU,JIAOYOUCAOZUOXITONGWANCHENGIOQINGQIU,RANHOUHUIDIAOZIJI。

ERReactorSHICHAXUNCAOZUOXITONG,FASHENGSHIJIANDESHIHOU,ZIJIZAIDUICAOZUOXITONGTONGBUIOQINGQIU,WANCHENGHOUZAIHUIDIAOZHUCEDECHULIHANSHU。

YINCIERZHEDEQUBIEZAIYUIOQINGQIUSHIOSLAIZUO,HUANSHIYINGYONGCENGLAIZUO,JIYIBUYUTONGBUIO。

YIBUIOZAIwindowsSHANGBIJIAOCHENGSHU,ZHICHIWANSHANHEGAOXIAO,ERZAILinuxDENGUnixXILIECAOZUOXITONGSHANGZHICHIDEBUSHIHENHAO,SUOYIDADUOYIReactorMOSHIWEIZHU。

聯系

SHEJIDAOGAOXIAOIOKUANGJIADOUSHIYONGLEIODUOLUFUYONGYUJIYUSHIJIANDEFANGSHI,LAIJIANGQINGQIUDECHULIGUOCHENG“JIAOCHAHUA”,BINGXINGHUA,YIBUHUA,TONGSHIJINLIANGDESHIYONGDICENGOSTIGONGDEZHICHIGONGNENGLAIDADAOGAOXIAO。





結束語


TProactorWEIDUOGEPINGTAITIGONGLEYIGETONGYONG、DANXING、KEPEIZHIDEGAOXINGNENGTONGXUNZUJIAN,SUOYOUNEIXIEZAIFULU2ZHONGTIDAODEWENTIDOUBEIHENHAODIYINZANGZAINEIBUSHIXIANZHONGLE。

江苏快三开奖结果CONGSHANGMIANDETUZHONGWOMENKEYIKANCHUC++RENGJIUSHIBIANXIEGAOXINGNENGFUWUQIZUIJIAXUANZE,SUIRANJavaYIJINSUIQIHOU。RANERYINWEIJavaBENSHENSHIXIANSHANGDEWENTI,QIZAIWindowsSHANGBIAOXIANBUJIA(ZHEYIJINGYINGGAICHENGWEILISHILEBA)。

XUYAOZHUYIDESHI,YISHANGZHENDUIJavaDECESHI,DOUSHIYILUOSHUJUDEXINGSHICESHIDE,WEISHEJIDAOSHUJUDECHULI(YINGXIANGXINGNENG)。

江苏快三开奖结果ZONGGUANAIOZAILinuxSHANGDEKUAISUFAZHAN[], WOMENKEYIYUJILinuxNEIHEAPIJIANGHUITIGONGDALIANGGENGJIAQIANGJIANDEYIBUAPI, RUCIYILAIYIHOUJIYUCIERSHIXIANDEXINDEEngine/DENGDAICELVEJIANGNENGQINGSONGDIJIEJUENENGYONGXINGFANGMIANDEWENTI,BINGQIEZHEYENENGRANGBIAOZHUNACE ProactorJIEKOUSHOUYI。

FULU I

TProactorZHONGSHIXIANDEEngines HE DENGDAICELVE

引擎類型等待策略操作系統
POSIX_AIO (true async)
aio_read()/aio_write()
aio_suspend()
Waiting for RT signal
Callback function
POSIX complained UNIX (not robust)
POSIX (not robust)
SGI IRIX, LINUX (not robust)
SUN_AIO (true async)
aio_read()/aio_write()
aio_wait() SUN (not robust)
Emulated Async
Non-blockingread()/write()
select()
poll()
/dev/poll
Linux RT signals
Kqueue
generic POSIX
Mostly all POSIX implementations
SUN
Linux
FreeBSD

FULU II

江苏快三开奖结果SUOYOUTONGBUDENGDAICELVEKEHUAFENWEILIANGZU:

  • edge-triggered (e.g. Linux實時信號) – signal readiness only when socket became ready (changes state);
  • level-triggered (e.g. select()poll(), /dev/poll) – readiness at any time.

RANGWOMENKANKANZHELIANGZUDEYIXIEPUBIANDELUOJIWENTI:

  • edge-triggered group: after executing I/O operation, the demultiplexing loop can lose the state of socket readiness. Example: the “read” handler did not read whole chunk of data, so the socket remains still ready for read. But the demultiplexor loop will not receive next notification.
  • level-triggered group: when demultiplexor loop detects readiness, it starts the write/read user defined handler. But before the start, it should remove socket descriptior from theset of monitored descriptors. Otherwise, the same event can be dispatched twice.
  • Obviously, solving these problems adds extra complexities to development. All these problems were resolved internally within TProactor and the developer should not worry about those details, while in the synch approach one needs to apply extra effort to resolve them.

[6] TProactor (ACE compatible Proactor).
www.terabit.com.au

[7] JavaDoc java.nio.channels

[8] JavaDoc Java.nio.channels.spi Class SelectorProvider

[9] Linux AIO development
, and

GENGDUO

江苏快三开奖结果Ian Barile “I/O Multiplexing & Scalable Socket Servers”, 2004 February, DDJ

Further reading on event handling

The Adaptive Communication Environment

Terabit Solutions

GUANYUZUOZHE

Alex Libman has been programming for 15 years. During the past 5 years his main area of interest is pattern-oriented multiplatform networked programming using C++ and Java. He is big fan and contributor of ACE.

Vlad Gilbourd works as a computer consultant, but wishes to spend more time listening jazz :) As a hobby,he started and runs  website.


參考材料



posted on 2015-07-09 11:00 Khan 閱讀(442) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。

網站導航:                管理


<2015年7月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

導航

統計

公告

現在時刻

IM在線情況:

常用鏈接

留言簿(33)

隨筆分類(220)

隨筆檔案(164)

相冊

技術

友情鏈接

最新隨筆

搜索

積分與排名

最新隨筆

最新評論

閱讀排行榜

評論排行榜