Netty源碼解析01 - 源碼準(zhǔn)備

目標(biāo)

  • 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是一個(gè)異步事件驅(qū)動(dòng)的網(wǎng)絡(luò)應(yīng)用程序框架,用戶快速開(kāi)發(fā)可維護(hù)的高性能協(xié)議服務(wù)器和客戶端

Netty架構(gòu)圖

image.png

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是一個(gè)NIO客戶端服務(wù)器框架,可快速輕松開(kāi)發(fā)網(wǎng)絡(luò)應(yīng)用程序,極大的簡(jiǎn)化了網(wǎng)絡(luò)編程。

快速簡(jiǎn)便 并不意味著最終的應(yīng)用程序?qū)⒃馐芸删S護(hù)性或性能問(wèn)題的困擾。Netty經(jīng)過(guò)精心設(shè)計(jì),結(jié)合了許多協(xié)議,最終成功找到一個(gè)無(wú)需妥協(xié)即可輕松實(shí)現(xiàn)開(kāi)發(fā),性能,穩(wěn)定性和靈活性的方法。

Netty特征

設(shè)計(jì)

  • 適用于各種傳輸類(lèi)型的統(tǒng)一API-阻塞和非阻塞套接字
  • 基于靈活且可擴(kuò)展的事件模型,可將關(guān)注點(diǎn)明確分離
  • 高度可定制的線程模型-單線程,一個(gè)或多個(gè)線程池,例如SEDA
  • 真正的無(wú)連接數(shù)據(jù)報(bào)套接字支持(從3.1開(kāi)始)

使用方便

  • 記錄良好的Javadoc,用戶指南和示例

  • 沒(méi)有其他依賴關(guān)系,JDK 5(Netty 3.x)或6(Netty 4.x)就足夠了

  • 注意:某些組件(例如HTTP / 2)可能有更多要求。請(qǐng)參閱 需求頁(yè)面 以獲取更多信息。

性能

  • 更高的吞吐量,更低的延遲
  • 減少資源消耗
  • 減少不必要的內(nèi)存復(fù)制

安全

  • 完整的SSL / TLS和StartTLS支持

Netty 本地環(huán)境搭建

  • Netty 的github repo fork 代碼到自己倉(cāng)庫(kù)
image.png
  • 將netty 源碼clone到本地
git clone https://github.com/nuo-promise/netty.git
git checkout -b master
git fetch upstream
git reset --hard upstream/master
  • 使用Idea打開(kāi)netty源碼

打開(kāi)之后要過(guò)一會(huì),因?yàn)閚etty需要查找依賴

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>

image.png
  • 然后執(zhí)行 install
image.png

總結(jié)

Netty 源碼解析準(zhǔn)備工作已經(jīng)完成,下面我們一起觀摩Netty的三高實(shí)現(xiàn)原理吧。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容