Netty internally implements a message processing main framework

1. The EventExecutorGroup maintains multiple message loops internally, and each group is monitored and called back by an EventLoop (EventExecutor). The specific implementation class MultithreadEventExecutorGroup: Internally uses children to maintain multiple EventLoops. The default allocation strategy is to allocate EventLoop to each channel in turn. An eventLoop loops through multiple connections to get messages. This ensures that messages per connection are single-threaded.

2. The specific implementation of EventLoop is EpollEventLoop or NIOEventLoop. The internal logic is that each obj corresponds to a thread, a blockingqueue, and an event loop. In each cycle, according to ioRatio, io event monitoring and processing corresponding callbacks are performed respectively. Among them, processReady calls back each handler. runAllTasks calls back other tasks in the LinkedBlockingQueue in turn, which may be thrown over in the handler as runnables, and time-based scheduling will also have runnables

3. processReady process

processReady->AbstractEpollUnsafe.epollInReadyRunnable->EpollServerSocketUnsafe.epollInReady->pipeline.fireChannelRead->各个handler

4. Callback in handler

 ctx.executor().execute(command);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326366088&siteId=291194637