Jan 09, 2021

The working principle of the multiplexer

Leave a message

select

The select multiplexer is an alternative method, which has been replacing all related kernel processes and checking their process status. Before processing the kernel process transaction, the app will copy the user connection request related data from the kernel space to the user space.

The shortcomings of this multiplexer are as follows:


Because in most cases, the kernel process is not in a normal state, and only a small part will be in a usable state. So most of the results in this case are meaningless

Since the appropriate volume is at least achieved by quantity, the number of kernel processes it can handle is limited, that is, the maximum number of concurrent connections that it can handle is limited

Copying from kernel space to user space is expensive.

polling

The working principle of the poll multiplexer is almost the same as that of the select. The difference is that since it is appropriately implemented by a linked list, it theoretically has no limit on the number of kernel processes to be processed, that is, the maximum concurrent connection that it can handle. There is no limit to the number (of course, it must be added to the ulimit of the maximum file length that can be opened in the current system).


vote

The epoll multiplexer is an enhancement and improvement to select and poll. Therefore, the epoll multiple replacement model is also called the epoll event-driven model.

In addition, the data used by the application program is no longer copied from the kernel space to the user space, but uses the mmap zero copy mechanism, which greatly reduces the system overhead.


Question: After the epoll multiplexer is notified of the correct progress of the kernel, the multiplexer will process it immediately. Will it be immediately placed in the appropriate position?


Answer: No. According to different processing methods, it can be divided into two processing modes: LT mode and ET mode.


LT mode

LT, Level Triggered, the horizontal trigger mode means that as long as the kernel process's ready notification is temporarily not processed by epoll for some reason, the kernel process will periodically notify epoll of its appropriate information. It supports two communication methods: BIO and NIO.


ET mode

ET, Edge Triggered, edge trigger mode is the only communication method that supports NIO. When the ready information of the kernel process will only notify epoll once, regardless of whether epoll processes the notification. There will be situations where the ready notification is ignored, that is, the connection request is lost.

Copyright statement: This is the original article of the CSDN blogger "Christy001", which follows the CC 4.0 BY-SA copyright agreement. Please attach the link to the analyst's source and this statement for reprinting.


Send Inquiry