Why to use Netty

Source: Internet
Author: User

Reasons to choose Netty
Before I begin this section, I'll start with a story of my own experience: There were two project groups that used the NIO programming technology, a project team chose to develop the NIO server, directly using the JDK native API, the results 2 months later, their NIO service end is not stable, problem frequency. Because NIO communication is one of their core components, the project's progress has been severely impacted and the leadership is furious. Another project group directly uses Netty as the NIO server, the business's custom development workload is very small, the tests show that the function and performance are fully met, the project team has little extra time and effort on the NIO server, and the project is progressing smoothly.
The different experiences of these two project groups remind us that the development of high-quality NIO programs is not a simple matter, removing the inherent complexities and bugs of NiO, as a NIO server needs to be able to handle the network flash, the client's repeated access, the client's security authentication, the message codec, half-packet read and write, etc. , if you don't have enough NIO programming experience to accumulate, the stability of a NIO framework often takes six months or longer. What is even worse is that once a problem occurs in the production environment, it often leads to interruption of service calls across nodes, which can lead to an outage of the entire cluster environment and the need to restart the server, which can result in a huge loss of downtime.
From the maintainability point of view, because NIO uses asynchronous non-blocking programming model, and is an IO threading multi-link, its debugging and tracking is very troublesome, especially in the production environment, we can not effectively debug and tracking, often only rely on some log to assist the analysis, positioning is very difficult.

Reasons for not selecting Java native NiO programming
In this section, we summarize why it is not recommended for developers to use the JDK's NIO library directly for development reasons:
1) NiO class library and API complex, use trouble, you need to master selector, Serversocketchannel, Socketchannel, Bytebuffer, etc.
2) need to have additional skills to pave the way, such as familiarity 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 program;
3) Reliability capacity, workload and difficulty are very large. For example, the client faces the disconnection, network flash, half packet read and write, failure cache, network congestion and exception stream processing, and so on, the characteristic of NIO programming is that the function development is relatively easy, but the reliability ability is very large and difficult.
4) The JDK NiO bug, such as the infamous Epoll bug, causes selector to empty polling and eventually leads to CPU 100%. The official claims that the issue was fixed in the JDK1.6 version of Update18, but until the JDK1.7 version of the problem still exists, but the probability of the bug has been reduced a few, it is not fundamentally resolved.
For these reasons, in most scenarios, I don't recommend using the JDK's NIO libraries directly, unless you are proficient in NIO programming or have special needs, in most business scenarios we can use the NIO framework Netty for NIO programming, which can be both client and server, It also supports UDP and asynchronous file transfer, which is very powerful.

In the next section, let's see why Netty is chosen as the basic communication framework.

Why Choose Netty
Netty is one of the industry's most popular NIO frameworks, and its robustness, functionality, performance, customisation, and scalability are among the best in its kind, and it has been validated by hundreds of commercial projects, such as the RPC framework for Hadoop Avro using Netty as the underlying communication framework. Many other industry-leading RPC frameworks also use Netty to build high-performance asynchronous communication capabilities.
Through the analysis of Netty, we summarize its advantages as follows:
1) Easy to use API, low development threshold;
2) Powerful, preset a variety of codec functions, support a variety of mainstream protocols;
3) Strong customization ability, the communication framework can be flexibly expanded through Channelhandler;
4) High performance, through the comparison with other industry mainstream NIO framework, Netty of the comprehensive energy optimization;
5) Mature, stable, netty fixed all of the JDK NiO bugs that have been found, and 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 repaired in time, and more new features will be added;
7) experienced a large-scale commercial application test, quality has been verified. In the Internet, big data, online games, enterprise applications, telecommunications software and many other industries have been successful commercial, it proves that it can fully meet the commercial applications of different industries.
Because of these advantages, Netty is becoming the preferred framework for Java NIO programming.

Transferred from: http://ifeve.com/netty-2-6/

Why to use Netty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.