events区域定义的是NGINX处理连接的设置

定义每个worker进程能打开的最大并发连接数

worker_connections定义的每个worker进程所能打开的最大并发连接数,但不是max_clients,因为worker_connections定义的是每个worker进程的最大并发连接数,so~max_clients应该是 worker_connections*worker_peocesses。

worker_connections number

Syntax: worker_connections number;
Default:
worker_connections 512;
Context: events
Sets the maximum number of simultaneous connections that can be opened by a worker process.

It should be kept in mind that this number includes all connections (e.g. connections with proxied servers, among others), not only connections with clients. Another consideration is that the actual number of simultaneous connections cannot exceed the current limit on the maximum number of open files, which can be changed by worker_rlimit_nofile.

定义NGINX并发连接的处理方法
use method

Syntax: use method;
Default: —
Context: events
Specifies the connection processing method to use. There is normally no need to specify it explicitly, because nginx will by default use the most efficient method

@> NGINX在并发处理上之所以能够强于apache,便是因为nginx默认的并发连接处理方式为epoll(异步非阻塞),而apache是select(同步阻塞),如官方文档所说,默认选择的就是最优的没事别改这个

i> NGINX处理新的连接请求从方法
如果开启了accept_mutex,哪个就由各个worker轮流去处理新的连接请求,如果不开启,那么每有一个新的请求后就会唤醒(通知)所以的worker进程,但是真正处理这个请求的只能有一个worker,就会出现惊群问题,参考文献:Nginx的accept_mutex配置

accept_mutex on | off

Syntax: accept_mutex on | off;
Default:
accept_mutex off;
Context: events
If accept_mutex is enabled, worker processes will accept new connections by turn. Otherwise, all worker processes will be notified about new connections, and if volume of new connections is low, some of the worker processes may just waste system resources.

There is no need to enable accept_mutex on systems that support the EPOLLEXCLUSIVE flag (1.11.3) or when using reuseport.
Prior to version 1.11.3, the default value was on.

Last modification:January 28th, 2019 at 10:28 pm