Netty | rectify thread model

Two common business scenarios

  • CPU-intensive: computing type;
  • IO-intensive: waiting type, such as relying on other microservices and databases;

CPU intensive

  • Keep the current thread model and reuse the threads bound in NioEventLoop;
  • In the current thread model, the number of threads bound in NioEventLoop: Runtime.getRuntime().availableProcessors() * 2;
  • Considering the Docker situation, you can set a parameter io.netty.availableProcessors, and then set the number of threads to io.netty.availableProcessors * 2;
  • When tuning, you can directly set the parameter io.netty.eventLoopThreads to set the number of threads bound in NioEventLoop;

IO intensive

  • Rectify the thread model, and independently create a "thread pool" to handle business;
    • Method 1: Use JDK Executors in the handler;
    • Method 2: When adding a handler, specify an EventExecutorGroup, code example:
EventExecutorGroup eventExecutorGroup = new UnorderedThreadPoolEventExecutor(10);
pipeline.addLast(eventExecutorGroup, serverHandler);
Why is NioEventLoopGroup not used in the sample code of Method 2?
  • When the parameter SINGLE_EVENTEXECUTOR_PER_GROUP is set to true, the code in the Handler will only be executed in one thread in the NioEventLoopGroup, so it is single-threaded, and requests have to be queued and waited;

Intelligent Recommendation

Netty features and thread model

Zero copy hard driver - kernel buffer - protocol engine only DMA copy avoids cpu copy There was actually a cpu copy of kernel buffer - socket buffer, but the copied information can rarely be ignored; ...

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...

More Recommendation

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...

【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...

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

Top