Netty Quick Start (06) Netty Introduction

In front of a brief introduction of the Java I / O and NIO, wrote a sample program.

Java I / O is blocked, it supports multiple concurrent order, we should start a thread for each link, the results of this approach is that in the case of massive link is created massive thread, even with the thread pool to ease , it is a temporary solution. So, Java I / O is not suitable for high-performance concurrent network programming needs.

NIO's appearance is to solve this problem, a thread can focus NIO multiple links to solve the problem of thread, front also demonstrates how to use NIO programming. We can see the use of NIO is very complex, can be said to be full of traps, not very experienced programmer in network programming, it is difficult to write NIO normal procedure, even senior programmer is not recommended.

Netty Introduction

More fun is to write a program that case, there will be a lot of framework to solve a variety of problems, such as JDBC directly write very complex, and so there will hibernate and mybatis framework that allows developers easier. NIO programming is the same, there have been a lot of framework, I believe many people have heard of mina framework, and netty same person. The netty is the most popular NIO framework to solve programming problems. We opened netty's official website, https: //netty.io, Home top is netty description:

file

Translated into Chinese is:

Netty is a provider of asynchronous, event-driven network application framework and tools to rapidly develop high-performance, high-reliability network server and client programs.

NIO also used to develop such a program, but it is complicated, if netty, can be very simple and very rapid development of high performance and high reliability of the program, the framework architecture picture is on the front page of netty:

file

We have also seen in the simple model introduced Linux IO time. netty divided into three parts, one is the core of the (Core), a transport service is part of (Transport Services), as well as a section provides protocol support (Protocol Support). We introduced earlier in the NIO buffer, while the core portion has a netty netty set of custom defined Byte Buffer, that is, in FIG. Zero-Copy-Capable Rich Byte Buffer, NIO buffer the complex, but also read and write manual switching mode not easy to understand, netty of Byte Buffer much better.

The core section also defines a set of general-purpose communication API (Universal Communication API), regardless of the program to go tcp protocol, or udp protocol, or other, all through a unified API communication.

The core section also provides an extensible event model (Extensible Event Model), is based on the event. These three parts together constitute the core part of netty.

In part protocol support, providing support common communication protocols, such as http, tcp, and so on. In addition to the communication protocol also provides support for common codec protocol. In the part of the transport service, providing a common transport support services. According can be seen on the picture.

Netty properties

netty feature on the home page of the official website listed out, is in English, we translate:

In design terms:

1) a unified API, for different protocols (blocking and non-blocking)

2) based on a flexible, scalable event-driven model (SEDA)

3) highly customizable threading model

4) Socket reliable support for connectionless data (UDP)

In terms of performance:

1) better throughput, low latency

2) more provincial resources

3) minimize unnecessary memory copy (which is also one of the reasons fast)

Safety aspects:

Full SSL / TLS and STARTTLS support

In terms of ease of use:

1) complete Java doc, user guide and sample (personally feel is not perfect, the country's only twelve books can)

2) depends only on JDK1.6 (netty 4.x)

netty is a very popular frameworks, there are used in many large and distributed framework data framework, many large domestic and foreign companies also are using (such as domestic BAT, etc.), are interested can inquire about, this is no longer an example child. netty is a framework, from the process of learning netty, we can also learn a lot of programming skills, netty code also worthy of us to read, learn a lot from there.

This article from the blog article multiple platforms OpenWrite release!

Guess you like

Origin juejin.im/post/5e1c3198e51d451c58017bcf