Moment For Technology

Understand multiplexing

Posted on Oct. 3, 2022, 5:41 a.m. by Matthew Harrison
Category: The back-end Tag: The back-end

Don't understand select, poll, epoll? After referring to numerous articles and books, record my understanding here!

Multiplexing is essentially an optimization idea, optimized from N-N to 1-N by listening for events or polling descriptors. In network programming, SELECT and epoll are the implementation of the above ideas, and in Redis is the basic model of IO multiplexing

Select and poll

When looking at many articles, found that a lot of articles are released select source. While the idea of exploring the source code is correct, it is a direct dissuader for novices (I, c++ code is a long story) so I'm just going to talk about the idea here. Select is processed by polling fd_set(a collection of file descriptors) to verify that an event has occurred. And poll and SELECT are just different implementation details, are essentially polling collections


Epoll registers event and callback functions, in other words, event-driven programming, that is, not an active polling collection. Obviously, event-driven improves the speed at which handlers respond to events. For example, a kindergarten child broke the vase, the teacher asked the children one by one "did you break the vase?" However, epoll teacher made an appointment with the children in advance (event-driven), so epoll teacher just waited for Xiao Ming to admit his mistake

Application scenarios of multiplexing

Network programming

In network programming, a data interaction usually consists of data arrival and data replication. Multiplexing is achieved by using a single thread or a small number of threads in the server to process multiple TCP connections

About (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.