Thread model in Netty

tags: Java technology  The internet  java  netty

The core concept in Netty isEvent loop (EventLoop), Which is actually Reactor in Reactor mode,Responsible for monitoring network events and calling event handlers for processing.In the 4.x version of Netty, the network connection and EventLoop have a stable many-to-one relationship, while EventLoop and the Java thread have a one-to-one relationship. The stability here means that once the relationship is determined, it will not change. In other words, a network connection will only correspond to a single EventLoop, and an EventLoop will only correspond to a Java thread, soA network connection will only correspond to a Java thread.

A network connection corresponds to a Java thread. What are the benefits? The biggest advantage is that the event processing for a network connection is single-threaded, which avoids various concurrency problems.

Another core concept in Netty isEventLoopGroupAs the name implies, an EventLoopGroup is composed of a set of EventLoops. In actual use, two EventLoopGroups are generally created, one is called bossGroup and the other is called workerGroup. Why are there two EventLoopGroups?

This is related to the mechanism by which socket handles network requests. The socket handles TCP network connection requests. It is in an independent socket. Whenever a TCP connection is successfully established, a new socket is created, and then the TCP connection is read and written. Completed by the newly created socket. In other wordsProcessing TCP connection requests and read and write requests is done through two different sockets.When we discussed network requests above, in order to simplify the model, we only discussed read and write requests, but did not discuss connection requests.

In Netty, bossGroup is used to handle connection requests, and workerGroup is used to handle read and write requests.After bossGroup has processed the connection request, it will submit the connection to workerGroup for processing. There are multiple EventLoops in workerGroup. Which EventLoop will be handed over to the new connection for processing? This requires a load balancing algorithm, the one currently used in Netty isPolling algorithm. 

Intelligent Recommendation

013. NETTY thread model

Introduction to Netty Netty is a high-performance, high-scalable asynchronous event-driven network application framework, which greatly simplifies network programming such as TCP and UDP clients and s...

Netty thread model and basics

Why use Netty Netty is an asynchronous event-driven web application framework for rapid development of maintainable high-performance and high-profile servers and clients. Netty has the advantages of h...

Netty thread model and gameplay

Event cycle group   All I / O operations in Netty are asynchronous, and the asynchronous execution results are obtained by channelfuture. Asynchronously executes a thread pool EventLoopGroup, it ...

Netty - Thread Model Reactor

table of Contents Thread model 1, traditional IO service model 2, Reactor mode reactor Three modes: to sum up Netty model Excommissum Thread model 1, traditional IO service model Blocked IO mode Get i...

Netty thread model [next]

Hey everyone, I amJava small white 2021。 The programmer of the halfway is in the development of aircraft, and the opportunity to find a more interesting thing under the development of a surveying cour...

More Recommendation

【Netty】 thread model

content 1. Single Reactor single thread 2. Single Reactor Multi -thread 3. Reactor Main Strike Model Single -threaded model (single Reactor single thread) Multi -threaded model (single Reactor multi -...

Netty entry thread model

Single-threaded model: the boss thread is responsible for connection and data reading and writing Hybrid model: the boss thread is responsible for connection and data reading and writing, and the work...

Redis source code parsing: 09redis database implementations (key operation, key timeout function key space notification)

This chapter of the Redis database server implementations are introduced, indicating achieve Redis database-related operations, including key-value pairs in the database to add, delete, view, update a...

PAT B1041-B1045 Question

1、b1041 2、b1042 3、b1043 4、b1044 5、b1045...

Sorting Algorithm - Overview

Seven commonly used sorting algorithm: 1w integers sorted tested Explain the principles of: 1, direct insertion sort be a sorted array A, an empty array B, once the elements A B into a specific positi...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top