Five communication models of the operating system
1. Blocking I/O
Is our common socket, the listening port receives the message to process, and returns the result to the client
Waits until the I/O operation is complete and does not give control to the program. Socket defaults to blocking mode
The application calls an IO function, causing the application to block and waiting for the data to be ready. If the data is not ready, wait .... Data ready, copy from kernel to user space, Io function return success instruction, program continues execution
2. Non-blocking I/O
Non-blocking IO calls IO functions over and over again, unlike blocking, when the IO function is invoked, the kernel immediately returns to the wrong interface, which continues to invoke the function recv () of the query result until the correct result is received, and the process is blocked in the process.
Non-blocking-mode sockets are not easy to use compared to blocking-mode sockets. Using non-blocking mode sockets, you need to write more code, however, Non-blocking sockets in the control of the establishment of multiple connections, the data received and received uneven, time is uncertain, the obvious advantages
3, I/O multiplexing model is mainly select and Epoll; for an IO port, two calls, two returns, there is no advantage over blocking IO; The key is to be able to monitor multiple IO ports simultaneously;
The I/O multiplexing model uses the Select, poll, and Epoll functions, which also block processes, but unlike blocking I/O, these two functions can block multiple I/O operations at the same time. And can be multiple read operations, multiple write I/O functions to detect, until there is data readable or writable, the real call I/O operation function
Interested can go and see NiO
4. Signal drive I/O First we allow the socket to signal-drive I/O, and install a signal-processing function, and the process continues to run without blocking. When the data is ready, the process receives a sigio signal that the I/O operation function can be invoked in the signal processing function to process the data.
5. Asynchronous I/O model
when an asynchronous procedure call is issued, the caller cannot immediately obtain the result. When the part that actually handles this call is finished, it notifies the caller of the input and output operation through the state, the notification, and the callback
Five modes of communication for interface invocation
1. Synchronous Point-to-Point service mode
Is that we usually send HTTP requests, wait for the server to return the interface, in the process of the request has been waiting for the result, so that is synchronous
2. Asynchronous point-to-point message Mode 1
after the client makes a request, the program continues executing and notifies the program by the callback function when the server is finished processing
3. Asynchronous point-to-point message Mode 2
increase the intermediary agent, such as CDN, Nginx, etc., to speed up the response of the server
4. Asynchronous broadcast message mode
distributing different messages to different servers based on message subscription distribution is also a kind of idea of distributed cluster processing, zookeeper is this way
5, go to the center of the distributed type
Remove the control of the ESB bus, which removes the bottleneck of single point performance of the System Center, and the rear single point server forms a new dynamic network to form a stateless system
La La la ...