Netty's easy to understand --49.Scalable IO in Java multi-threaded version of the analysis (two)

Multi-threaded design

* Strategic threads is increased scalability, mainly used in multi-core processor

Worker (for our workGroup)

reactor should be able to quickly trigger processor

* The processor will slow down the reactor processing (reason: because the reactor will be issued to the sub-task handler, because it is single-threaded, so the task is distributed processor becomes more time, it will slow down the process of the reactor)

So shed some non-IO processing to another thread processing

Multiple threads reactor

reactor thread can be processed in the IO

Distribute the load to other reactor in

Load balancing, so that the CPU and IO rate matching

Worker thread:

* Shed non-IO processing to improve speed

reactor thread

Similar POSA2 Proactor designs

* Compared to re-compute-bound to event-driven process easier

It should still be a purely non-blocking calculation

* Enough to handle the load process

* However, it is difficult to perform IO overlap processing

The best action is able to read all of the first input to a buffer in the

Use thread pool can be adjusted and controlled

The number of threads is usually less than the number of clients

 Or multiple client initiates a connection with the reactor, we can see that it is handled by a thread pool requests

View handled thread pool,

Collaborative task

*Handoffs

Each task can be enabled or triggered calls next

It is very fast, but very fragile

Callbacks: for each processor to distributor

Set state, attachment, etc.

One kind of gof mediator mode

queue

For example: transfer buffers at some stage

Futures

Each task is to produce a result

In the above stage synergies join or wait / notify of

 Use PoolExecutor

* A harmonious working thread pool

* The main method is to execute (Runnable r)

*Controls for:

The kind of task queue

The maximum number of threads

The minimum number of threads

"Warm" and on-demand thread

Keep alive interval until the thread death

* If necessary, a new can replace the old

Saturated strategy:

* Blocking, removing, production - runs, etc.

Multiple threads reactor

* Use the Reactor Pools

Rate matching for the CPU and IO

静态的和动态的构建

*每一个都拥有自己的selector、线程、调度循环

主要的acceptor会分发(处理器)给其他的reactor;

 使用多Reactor

mainReactor理解成netty中的bossGroup(parentGroup)

subReactor理解成netty中的workGroup(childGroup)

 使用其他的NIO特性

*每个Reactor对应着多个selectors

将不同的处理器绑定到不同的IO事件。

需要一些同步来协调。

*文件传输

自动化的文件传输到网络或网络传输到文件的拷贝

*记忆映射文件

获取文件通过buffers

*Direct buffers

能够实现0拷贝传输

有些创建和结束

对于那些长连接它的效果是更好的

基于连接的扩展

*而不是单个服务请求

客户端连接

客户端发送一系列的信息和请求

客户端断开连接

例子:

数据库和事务的监控

 

对java的API进行一些说明:

 

 

Guess you like

Origin blog.csdn.net/qq_37909508/article/details/91355773