Chapter 4 Netty Overview

4.1 Problems with native NIO

  1. NIO's class libraries and APIs are complex and cumbersome to use : you need to be proficient in Selector, ServerSocketChannel, SocketChannel, ByteBuffer, etc.

  2. Other additional skills are required: to be familiar with Java multithreaded programming, because NIO programming involves Reactor mode , you must be very familiar with multithreading and network programming, in order to write high-quality NIO programs.

  3. The development workload and difficulty are very large: for example, the client faces disconnection and reconnection, network flash, half-packet read and write, failure cache, network congestion and abnormal flow processing, etc.

  4. Bugs of JDK NIO: For example, the infamous Epoll bug, which will cause the Selector to poll empty, eventually resulting in 100% CPU. Until JDK version 1.7, the problem still exists and has not been solved

4.2 Netty official website description

Official website: https://netty.io/
Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients
Insert picture description here
Netty is an open source Java framework provided by JBOSS. Netty provides an asynchronous, event-driven network application framework for rapid development of high-performance, high-reliability network IO programs

Netty can help you develop a network application quickly and simply, which is equivalent to simplify and streamline the development process of NIO

Netty is currently the most popular NIO framework. Netty has been widely used in the Internet, big data distributed computing, game industry, and communication industries . Netty is used in the well-known Elasticsearch and Dubbo frameworks .

4.3 Advantages of Netty

Netty encapsulates the API of the NIO that comes with JDK to solve the above problems.

  1. Elegant design: unified API blocking and non-blocking Socket for various transmission types; based on a flexible and extensible event model, which can clearly separate concerns; highly customizable thread model-single thread, one or more thread pools .

  2. Easy to use: well-documented Javadoc, user guide and examples; without other dependencies, JDK 5 (Netty 3.x) or 6 (Netty 4.x) is sufficient.

  3. High performance and higher throughput: lower latency; reduced resource consumption; minimized unnecessary memory replication.

  4. Security: Full SSL / TLS and StartTLS support.

  5. Community is active and constantly updated: the community is active, the version iteration cycle is short, the discovered bugs can be repaired in time, and at the same time, more new features will be added

4.4 Netty release notes

  1. The netty version is divided into netty3.x and netty4.x, netty5.x

  2. Because Netty5 has a major bug, it has been abandoned by the official website. The current recommended version is the stable version of Netty 4.

  3. The currently available versions of the official website are netty3.x netty4.0.x and netty4.1.x

  4. In this course, we explain Netty4.1.x version

  5. netty download address: https://bintray.com/netty/downloads/netty/
    Insert picture description here

Published 138 original articles · Like 3 · Visitor 7234

Guess you like

Origin blog.csdn.net/weixin_43719015/article/details/105166930
Recommended