Comparison of Java Native and Netty Implementation of NIO Programming

The status quo of Java native NIO programming

(1) NIO's class library and API are complicated and troublesome to use. You need to be proficient in Selector, ServerSocketChannel, SocketChannel, ByteBuffer, etc.

(2) Need to have other additional skills to pave the way, such as familiarity with Java multi-threaded programming. This is because NIO programming involves the Reactor model. You must be very familiar with multithreading and network programming to write high-quality NIO programs.

(3) The reliability and ability are supplemented, and the workload and difficulty are very large. For example, the client faces problems such as disconnection and reconnection, network flashing, half-packet reading and writing, failed cache, network congestion, and abnormal code stream processing. The feature of NIO programming is that the function development is relatively easy, but the reliability and ability are complemented. The amount and difficulty are very large.

(4) JDK NIO's BUG, ​​such as the notorious epoll bug, it will cause the Selector to be empty polling, and eventually lead to 100% CPU. The official claimed that the updatel8 version of JDK 1.6 fixed the problem, but the problem still exists until the JDK 1.7 version, but the probability of occurrence of the BUG has been reduced a little, and it has not been fundamentally solved.

Netty's current status of NIO programming

Netty is one of the most popular NIO frameworks in the industry. Its robustness, functionality, performance, customizability and scalability are second to none among similar frameworks. It has been verified by hundreds of commercial projects, such as Hadoop Avro's RPC framework Avro uses Netty as the underlying communication framework. Other mainstream RPC frameworks in the industry also use Netty to build high-performance asynchronous communication capabilities.

Through the analysis of Netty, we summarize its advantages as follows.

  1. API is easy to use, and the development threshold is low

  2. Powerful, preset multiple codec functions, support multiple mainstream protocols

  3. Strong customization ability, can flexibly extend the communication framework through ChannelHandler

  4. High performance. Through comparison with other mainstream NIO frameworks in the industry, Netty has the best overall performance

  5. Mature and stable. Netty fixes all JDK NIO BUGs that have been discovered. Business developers don’t need to worry about NIO BUGs anymore.

  6. The community is active, the version iteration cycle is short, the bugs found can be fixed in time, and more new features will be added

  7. After a large-scale commercial application test, the quality has been verified. Netty has been successfully commercialized in many industries such as the Internet, big data, online games, enterprise applications, and telecommunications software, which proves that it can fully meet the commercial applications of different industries.

Guess you like

Origin blog.csdn.net/cyb_123/article/details/107773643