http://www.javashuo.com/article/p-yeqleamk-kt.htmlhtml
http://www.javashuo.com/article/p-pzuajhks-bq.html多線程
- 厲害
-
單線程Reactor
![](http://static.javashuo.com/static/loading.gif)
- 另外一種畫法(意思差很少):
-
缺點:
- 當其中某個 handler 阻塞時, 會致使其餘全部的 client 的 handler 都得不到執行,
- 而且更嚴重的是, handler 的阻塞也會致使整個服務不能接收新的 client 請求(由於 acceptor 也被阻塞了)。
- 由於有這麼多的缺陷, 所以單線程Reactor 模型用的比較少。
- 這種單線程模型不能充分利用多核資源,因此實際使用的很少。
- 所以,單線程模型僅僅適用於handler 中業務處理組件能快速完成的場景
-
多線程的Reactor
![](http://static.javashuo.com/static/loading.gif)
- 另外一種畫法(意思差很少):
- 主從多線程Reactor模式
- mainReactor負責監聽鏈接,accept鏈接給subReactor處理,
- 爲何要單獨分一個Reactor來處理監聽呢?
- 由於像TCP這樣須要通過3次握手才能創建鏈接,
- 這個創建鏈接的過程也是要耗時間和資源的,
- 單獨分一個Reactor來處理,能夠提升性能。