Extending face questions:
Nginx What are the advantages?
Answer: Multiple IO multiplexing epoll model, CPU affinity, sendfile
Nginx talk about multi-channel IO multiplexing epoll model?
Answer: single-threaded model + non-blocking event callbacks way to solve the problem select the file handle limit, greatly improving the efficiency of concurrency.
Nginx's CPU affinity is what?
Answer: the CPU core and Nginx worker processes to bind to each worker process that is fixed on a cpu execution, reducing CPU cache miss, get good performance.
Nginx is what the sendfile
answer: 0copy after linux2.2, is transferring files only need to go through the kernel direct transmission, eliminating the need for frequent switching kernel mode and user mode.
As middleware
Nginx can be used as middleware between the various applications, he is an open source, high performance, reliable middleware HTTP proxy service.
Common middleware services are Apache, IIS
Nginx What are the advantages?
IO model using multiplexing epoll
After multiple requests to nginx will produce more socket streams, here are faced with multiple IO stream processing, if only blocking a thread processing will occur, which means that only one person visit the Web site, at the end of this person access a people can access, to solve this problem we introduce a multi-process multi-threaded processing and multiple IO multiplexing .
Multi-threaded and multi-process model of multi-channel IO multiplexing
processing a stream of I / O event only a thread. If you want to handle multiple streams, or multi-process or multi-threaded, efficiency is not very high. So to a thread to a multi-channel IO multiplexing mode.
Nginx Epoll model using
Stream [] IO understood as a plurality of streams
IO streams nonblocking mode
while true {
for i in stream[]; {
if i has data
read until unavailable
}
}
linux model
select Model -> poll model -> epoll model
select model
while true{
select(streams[]){
for i in stream[]; {
if i has data
read until unavailable
}
}
}
epoll model
Advantage 1: Solving the select model for file handles open FD limit
Advantage 2: The callback function callback mechanism to optimize efficiency model
while true{
select(streams[]){
for i in stream[]; {
if i has data
read until unavailable
}
}
}
CPU affinity
The CPU core and Nginx worker processes to bind to each worker process that is executed on a fixed cpu, reducing CPU cache miss, get good performance.
sendfile
Sendfile does not use the file transfer process: File-> kernel space -> User Space -> kernel space -> Socket
using the file transfer process sendfile: File-> kernel space -> Socket
With map: