In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "introduction to the high-performance principle of IO reuse of Nginx server". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. please follow the editor's train of thought to study and learn "the introduction of IO reuse of high-performance principle of Nginx server".
Import
The way Nginx handles IO is asynchronous and non-blocking. In addition to asynchronous non-blocking, there is a core reason for the high performance of Nginx: IO reuse.
What is IO reuse?
Starting with the simplest example, how do you normally handle a request after a request connection comes? As shown in figure 1
Each request from the browser will be assigned or a new process will be started to process the request. Switching between process contexts and starting new processes can be a waste of resources. How to optimize them? (hands up) turn multi-entry into multithreading. Then you have the optimization results shown in figure 2 below.
What's wrong with that? Think about it, a thread is the smallest unit of process scheduling, and if a process has multiple threads processing requests at the same time, then if the process terminates unexpectedly because of an exception, then all the threads it owns will terminate. In other words, the service is down. Haha, it's so exciting.
So IO reuse comes in handy ~ ~ We mentioned asynchronous non-blocking earlier, so let's design it this way, we design a process pool, event response daemon, and request service process. So, the process architecture of our server is shown in the following figure:
As shown in the figure above, we divided the server into three modules:
Process pool
Event response
Event registration
When the browser request arrives at the server, it first connects to the (3) requesting service process and registers an event. When the request sends data, a read event is generated. At this time, (2) the event response process will respond, handing the event to the (1) process pool and registering a write event at the same time. When the process pool finishes processing the request, it returns the result of the processing to the browser in response to the write event.
So what is the reuse of IO reuse?
IO reuse is a process that responds to real request events. What is essentially reused is the process.
Select and Epoll
When a read-write event occurs, the event daemon responds to the process pool and registers a write event, but how does the process pool know which socket has an event? So every time an event occurs, the event response process traverses all the socket connection handles to determine whether an event has occurred. This way of responding to an event is called the Select model.
How to optimize it? If every time an event occurs, it will be very efficient if you can know exactly which socket connected event. This way is called the Epoll model. For instance
If someone in the restaurant wants to check out, the waiter says to the boss, "someone wants to check out". The boss doesn't know which table is going to check out, so he needs to ask them one by one. This way is select, time complexity O (n).
If someone in the restaurant wants to check out, the waiter says to the boss: "check out at table 5". This way is epoll, time complexity O (1).
Understand the evolution of a high-performance server from a large point of view, and sum up: the concept of pool will greatly improve performance, this time we are talking about process pool, so is changing to thread pool (actually multi-process and multi-thread mode).
Thank you for reading, the above is the "introduction to the high-performance principle of Nginx server IO reuse" content, after the study of this article, I believe you have a deeper understanding of the high-performance principle of Nginx server IO reuse introduction, the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.