1

"What is the multiplexing mechanism for IO?"

This is an interview question with an annual salary of 50W. Unfortunately, 99% of people cannot answer it.

Hi, my name is Mic, a Java programmer who has been working for 14 years.

Today, I will share with you a network IO interview question.

The text answer to this question has been sorted into the 15W word interview document, and you can receive it from me.

Check out the experts' answers below.

Expert:

The core idea of the IO multiplexing mechanism is to allow a single thread to monitor multiple connections. Once a connection is ready, a read/write event is triggered.

Just notify the application to get this ready connection for read and write operations.

That is to say, a single thread can be used in the application to process multiple client connections at the same time, which increases the number of connections processed by the server while consuming less system resources.

In the implementation principle of the IO multiplexing mechanism, after the client requests to the server, when the client transmits data, in order to prevent the server from being blocked in the process of reading client data, the server will register the request. On the Selector multiplexer, the server does not need to wait at this time. It only needs to start a thread and block the ready channel on the polling multiplexer through selector.select(). That is to say, if a client connects After the data transmission is completed, the select() method will return the ready channel, and then perform the related processing.

image-20220710155428180

Common IO multiplexing mechanisms are implemented in the following ways: select, poll, and epoll.

These are all implementations of the IO multiplexing mechanism provided by the Linux system, where select and poll are based on polling to obtain ready connections.

And epoll is based on an event-driven approach to get ready connections. From a performance point of view, the event-driven approach is better than the polling approach.

Summarize

The IO multiplexing mechanism is a very important network communication basis.

In the usual business development, it is used less, but as the basic communication model in the middleware, it is the content that every senior engineer must master.

Remember to like, subscribe and follow.

file

Copyright notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated. Please indicate the source for Mic带你学架构 !
If this article is helpful to you, please help to follow and like, your persistence is the driving force for my continuous creation. Welcome to follow the WeChat public account of the same name to get more technical dry goods!

跟着Mic学架构
810 声望1.1k 粉丝

《Spring Cloud Alibaba 微服务原理与实战》、《Java并发编程深度理解及实战》作者。 咕泡教育联合创始人,12年开发架构经验,对分布式微服务、高并发领域有非常丰富的实战经验。