Netty: A non-blocking client/server framework

Source: Internet
Author: User
Tags fsm starttls

Netty: A non-blocking client/server framework

Chszs, reprint need to indicate. Blog home:Http://blog.csdn.net/chszs

Netty is an asynchronous event-driven network application framework that brings some new vitality to the development of Java Web applications. The Netty is comprised of protocol servers and clients that can be used to rapidly develop maintainable, high-performance software. The Netty application framework and its tools simplify network programming and are maintained by the Netty community.


Netty is also categorized as a NIO client/server framework, which enables fast and easy development of network applications, simplifying and rationalizing the network programming of TCP and UDP socket servers.

The built-in HTTP protocol supports WEBSOCKET, allowing the framework to run inside a servlet container. The new version of Netty supports both non-blocking I/O and blocking I/OS communication.

Features of the Netty:

1, transmission services include: socket and datagram, HTTP channel, virtual machine internal pipeline

2. The protocol supports the following extensions: HTTP, Web Socket, Google Protocol Buffer, ssl-starttls, large file transfer, RTSP, zlib or gzip compression, binary protocol, other legacy text formats

3. Core: Scalable event model, unified Communications API, 0 copy-capable byte buffer

Netty Design:

Designed for multiple transport types, Netty integrates a unified set of APIs, blocking, and non-blocking sockets. The Netty event model is extensible and allows for a clear separation of concerns. Netty's threading model provides the flexibility to choose between thread pools such as single-threaded or class-Seda, and threads are highly customizable, support for datagrams enables true, non-connected communication, and Netty's pipeline abstraction, combined with thread and dynamic variability, gives the framework a strong support.

Note: SEDA, which is staged event driven Architecture, is a staged, events-driven architecture. The idea of Seda is to split a task that was originally performed by one thread into a relatively independent number of stages. Each stage is performed by a dedicated set of threads, and the phases are used to interact with the queue. Using Seda method, only when the concurrency increases to a certain degree, concurrency becomes the bottleneck of the system to reflect the value. In the case of a single operation, the delay must be increased due to the queue's delivery.

You can refer to this paper "Seda:an Architecture for well-conditioned, scalable Internet Services"

Seda is an excellent high performance Internet server architecture model at UC Berkeley, designed to support large-scale concurrency processing, simplify system development, support processing monitoring, and support system resource management.

Two network server architecture models that are currently widely used:

1) Multithreaded server (threaded server)

How it works: For each request,dispatcher, it creates and assigns a thread that is responsible for the processing of the request. This method is also named (thread-per-request).


Advantage: Execution granularity is the entire process, the processing logic is clear and easy to develop.
Disadvantage: As the number of processing requests increases, there are too many threads that will cause concurrent execution. Excessive number of threads can lead to excessive overhead of system thread scheduling and resource contention, resulting in a sharp decrease in system performance, resulting in reduced system processing power.
Improvement measures: Introduction of thread pool (bounded thread pools)
The system can create up to a certain number of threads. When all the threads are running saturated, the newly arrived processing request can only wait, or be discarded.
Cons: Execution granularity is still a complete processing process, making it difficult to detect the root cause of system performance bottlenecks and adjust accordingly.

2) event-driven concurrency processing (event-driven Concurrency)

Divides the processing process into multiple steps, each of which is implemented as a finite state machine (FSM).
How it works: All processing requests are entered into the system as an event, which is passed to the appropriate FSM by the scheduler. The processing results of the FSM are also output to scheduler in event form. The new event is again forwarded to the next FSM by scheduler until the processing is complete.


Advantages:
1, with the increase in processing capacity, the system load is linear growth. When the system saturation processing capacity is reached, the processing power of the system will not decrease.
2, due to the individual processing steps to achieve, easy to carry out system monitoring and adjustment.
Disadvantages:
The design and implementation of scheduler is too complex and requires different implementations for different application and system logic changes.


Seda Architecture

(Approximate to Event-driven Concurrency, but none of the scheduler) separate each processing step into a single stage.


Stage structure:
1) An event Queue that accepts input;
2) an event Handler written by an application developer;
3) A controller is used to control the execution process. Including the number of concurrent threads, batch processing quantity, etc.;
4) A thread pool is used for concurrent processing;
The input to the stage is obtained through the event queue. The output of the stage is pushed to the event queue in the other stage as an event. This connection relationship between stages is specified by the application developer.
The problem: The Event queue reduces the coupling between modules, but slows down the response speed.


Performance and effectiveness:

The Netty not only provides good stability, but also provides better throughput and lower latency performance, limiting memory replication to the minimum requirements, and the 0 copy-capable byte-buffer feature enables the kernel to manage DMA replication. This reduces the burden on the CPU and the system bus, and improves the effectiveness of the framework.

Scalability and Integration:

The Netty is scalable, supports scaling to thousands of connection types, and has no performance bottlenecks while maintaining effectiveness. The reliability of these connections is very high and will not fail. Netty is easy to scale and build. Netty also offers flexible integration capabilities that can be integrated with environments such as Linux, Java, C #, C + +, Python, and more.

Security: Netty provides complete SSL/TLS and STARTTLS support.

Netty Official offers a number of guides, documentation, and Javadoc and examples for developers to refer to.

The current stable version of Netty is 4.0.23 version.

: http://dl.bintray.com/netty/downloads/netty-4.0.23.Final.tar.bz2

Netty: A non-blocking client/server framework

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.