《Netty官方文檔》本地傳輸接口
自4.016版本以來, Netty提供了本地的socket傳輸使Linux係統可以使用JNI(JAVA本地接口)。這個傳輸接口不僅有著高性能並且產生更少的垃圾,所以你也許會想嚐試使用一下。
使用本地傳輸接口
由於這個本地傳輸接口是與NIO傳輸接口兼容的,你隻需要查詢並替代以下的內容:
- NioEventLoopGroup → EpollEventLoopGroup
- NioEventLoop → EpollEventLoop
- NioServerSocketChannel → EpollServerSocketChannel
- NioSocketChannel → EpollSocketChannel
由於這個本地傳輸接口不在Netty core 核心代碼中,你需要修改你的pom.xml文件拉出netty-transport-native-epoll這部分代碼作為依賴:
kr.motd.maven os-maven-plugin 1.5.0.Final
...
io.netty netty-transport-native-epoll ${project.version} ${os.detected.name}-${os.detected.arch} ...
注意以上, 你需要指定正確的classifier配置作為依賴。在pom.xml文件extensions 擴展部分os-maven-plugin的os..detected.name和os.detected.arch 配置屬性會自動配置。需要更多信息,涉及the homepage of the os-maven-plugin.
想在一個 sbt項目中使用本地傳輸接口,請在加上線在libraryDependencies:
配置
“io.netty” % “netty-transport-native-epoll” % “${project.version}” classifier “linux-x86_64″
構建本地傳輸接口包
如果你已經有了本地傳輸接口的jar包,那你將不用自己去構建本地接口包了,因為jar包中已經包含了已經所需要的包並且會自動加載上。
去構建本地傳輸接口包,你需要使用64-bit核心的2.6及其以上版本的linux操作係統。並請安裝所需要的工具和庫:
# RHEL/CentOS/Fedora:
sudo yum install autoconf automake libtool make tar \ glibc-devel libaio-devel \ libgcc.i686 glibc-devel.i686
# Debian/Ubuntu:
sudo apt-get install autoconf automake libtool make tar \ gcc-multilib libaio-dev
最後更新:2017-05-19 10:25:45