Netty笔记之一:Netty 快速入门
netty是什么?
Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.
netty是一个异步的事件驱动(不同的阶段,对应不同的回调方法)的网络框架维护着高性能协议的服务器端和客户端的快速开发。
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.
Netty是一个非阻塞的io客户端服务端的框架可以快速并且简单的开发网络应用比如说客户端和服务端的协议。它极大的简化了网络编程流程比如说tcp或者udp socket服务器。
'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精简的设计从一些的协议比如说FTP,STMP,HTTP和一些基于二进制的传统协议获取的经验。因此,Netty成功的发现一种方式去实现轻松的开发,性能,稳定和灵妥协。活性而不需要任何的.
特征(Features)
设计
Unified API for various transport types - blocking and non-blocking socket
统一的api基于不同的传输类型-阻塞和非阻塞的socket.
Based on a flexible and extensible event model which allows clear separation of concerns.
基于灵活的可扩展的时间模型,允许明确的关注分离.
Highly customizable thread model - single thread, one or more thread pools such as SEDA
高度可定制的线程模型-单线程,一个或多个线程池比如说SEDA.
SEDA(Staged Event-Driven Architecture)的核心思想是把一个请求处理过程分成几个Stage,不同资源消耗的Stage使用不同数量的线程来处理,Stage间使用事件驱动的异步通信模式。
True connectionless datagram socket support (since 3.1).
真正的无连接的数据报socket支持(基于3.1版本).
使用简单
- Well-documented Javadoc, user guide and examples
详细的用户java文档,用户指南和demo - No additional dependencies, JDK 5 (Netty 3.x) or 6 (Netty 4.x) is enough
不需要额外的依赖,JDK 5 (Netty 3.x版本) 或者 6 (Netty 4.x版本)就足够了 - Note: Some components such as HTTP/2 might have more requirements. Please refer to the Requirements page for more information.
注意:一些组件比如说HTTP/2可能需要一些额外的依赖。
性能
- Better throughput, lower latency
更好的吞吐量,低延迟 - Less resource consumption
资源消耗减少 - Minimized unnecessary memory copy.
不必要的内存拷贝(零拷贝).
安全
Complete SSL/TLS and StartTLS support。
完全的SSl/tls 和 StartTLS的支持。
- core(核心模块):Extensible Event Model(可扩展的事件模型),Universal Communication API(通用的通讯API),Zero-Copy-Capable Rich Byte Buffer(零拷贝的字节缓冲区)
- Transport Services(传输服务): Socket & Datagram,HTTp Tunnel,In-Vm Pipe
- Protocol Support(协议支持): HTTP & WebSocket,SSl.StartTLS,Google Protobuf,zlib/gzip Compression,Large File Transfer,RTSP(和流媒体有关),Legacy Text.Binary Protocols with Unit Testability
关于netty5废弃的原因
netty5的主要变化是使用了ForkJoinPool使得程序变得异常复杂,但是性能却没有得到可见的提升,并且维护多个版本的代码更新是个耗费精力的事情,所以废弃了netty5的主分支。
参考资料
netty官网