引言
入行Java几年以来,屡屡听闻同事讲述Netty的魅力,甚至有人说Tomcat和Jetty中的网络层对于Netty就像业余玩家对比职业玩家的区别,最近正好有时间,准备沉静下来好好学习一下Netty,而要学好Netty,就得从它的源码开始入手
Netty官网
- 介绍
netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients
大概的意思是说:Netty 是一个可以快速开发可维护,高性能的协议服务端和客户端的一个异步事件驱动的网络应用框架
- 架构图
特性
Netty的特性官网上分别从以下几点来描述
Design 设计
1. Unified API for various transport types - blocking and non-blocking socket
2. Based on a flexible and extensible event model which allows clear separation of concerns
3. Highly customizable thread model - single thread, one or more thread pools such as SEDA
4.True connectionless datagram socket support (since 3.1)
针对各种传输类型 - 阻塞和非阻塞Socket 提供了统一的API
基于灵活和可扩展的事件模型,允许关注点分离
高度定制化的线程模型 - 单线程, 一个或多个线程池,比如SEDA
真正的无连接数据报套接字支持
Ease of use 易用性
1. Well-documented Javadoc, user guide and examples
2. No additional dependencies, JDK 5 (Netty 3.x) or 6 (Netty 4.x) is enough
Note: Some components such as HTTP/2 might have more requirements. Please refer to the Requirements page for more information.
良好的Javadoc文档,使用指南和示例
不需要额外的依赖,Netty 3.x版本需要使用JDK5,Netty 4.x 需要使用JDK6即足够了
备注:有些组件如HTTP/2 可能需要更多的依赖,具体信息请查阅https://netty.io/wiki/requirements.html
Performance 性能
1. Better throughput, lower latency
2. Less resource consumption
3. Minimized unnecessary memory copy
更高的吞吐量,更低的时延
更少的资源消耗
最小化不必要的内存复制
Security 安全
1. Complete SSL/TLS and StartTLS support
- 完成支持SSL/TLS 和StartTLS 安全协议
还有最后一点 Community 社区活跃度
1. Release early, release often
2. the author has been writing similar frameworks since 2003 and he still finds your feed back precious!
经常发布,提前发布
自2003年以来,作者一直再编写类似的框架,以及珍视开发者的各项反馈!
Clone source code
源代码地址:netty
总结
最后奉上Netty之父Trustin Lee的github主页,膜拜一下Trustin Lee大神