目標
Netty 介紹
Netty架構(gòu)圖
Netty特性
Netty 本地環(huán)境搭建
Netty 本地Install
Netty介紹
Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.
Netty是一個異步事件驅(qū)動的網(wǎng)絡(luò)應(yīng)用程序框架,用戶快速開發(fā)可維護的高性能協(xié)議服務(wù)器和客戶端
Netty架構(gòu)圖
Netty is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP and UDP socket server.
'Quick and easy' doesn't mean that a resulting application will suffer from a maintainability or a performance issue. Netty has been designed carefully with the experiences earned from the implementation of a lot of protocols such as FTP, SMTP, HTTP, and various binary and text-based legacy protocols. As a result, Netty has succeeded to find a way to achieve ease of development, performance, stability, and flexibility without a compromise.
大概意思就是介紹Netty是一個NIO客戶端服務(wù)器框架,可快速輕松開發(fā)網(wǎng)絡(luò)應(yīng)用程序,極大的簡化了網(wǎng)絡(luò)編程。
快速簡便
并不意味著最終的應(yīng)用程序?qū)⒃馐芸删S護性或性能問題的困擾晦款。Netty經(jīng)過精心設(shè)計,結(jié)合了許多協(xié)議,最終成功找到一個無需妥協(xié)即可輕松實現(xiàn)開發(fā),性能,穩(wěn)定性和靈活性的方法骗奖。
Netty特征
設(shè)計
- 適用于各種傳輸類型的統(tǒng)一API-阻塞和非阻塞套接字
- 基于靈活且可擴展的事件模型碰声,可將關(guān)注點明確分離
- 高度可定制的線程模型-單線程钥勋,一個或多個線程池,例如SEDA
- 真正的無連接數(shù)據(jù)報套接字支持(從3.1開始)
使用方便
記錄良好的Javadoc售淡,用戶指南和示例
沒有其他依賴關(guān)系理张,JDK 5(Netty 3.x)或6(Netty 4.x)就足夠了
注意:某些組件(例如HTTP / 2)可能有更多要求。請參閱 需求頁面 以獲取更多信息召廷。
性能
- 更高的吞吐量凳厢,更低的延遲
- 減少資源消耗
- 減少不必要的內(nèi)存復(fù)制
安全
- 完整的SSL / TLS和StartTLS支持
Netty 本地環(huán)境搭建
- 從
Netty
的github repo fork 代碼到自己倉庫
- 將netty 源碼clone到本地
git clone https://github.com/nuo-promise/netty.git
git checkout -b master
git fetch upstream
git reset --hard upstream/master
- 使用Idea打開netty源碼
打開之后要過一會,因為netty需要查找依賴
Netty本地install
<pre class="cm-s-default" style="color: rgb(89, 89, 89); margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0);"># 在Linux 終端 netty 的根目錄下執(zhí)行 mvn -B clean install -Dmaven.javadoc.skip=true -Drat.skip=true -Djacoco.skip=true -DskipITs -DskipTests # 或者 idea 使用 mvn install,要是為了速度快 設(shè)置下 idea 的 maven 執(zhí)行參數(shù)</pre>
- 然后執(zhí)行 install
總結(jié)
Netty 源碼解析準備工作已經(jīng)完成,下面我們一起觀摩Netty的三高實現(xiàn)原理吧。