NGINX 全局(main)区域 重要设置

NGINX cpu缓存优化

worker_cpu_affinity可以锁定每个worker对应的CPU核心,提高缓存命中率

worker_cpu_affinity auto [cpumask]

具体作用参考官方文档,不做过多概述
Syntax: worker_cpu_affinity cpumask ...;
worker_cpu_affinity auto [cpumask];
Default: —
Context: main
Binds worker processes to the sets of CPUs. Each CPU set is represented by a bitmask of allowed CPUs. There should be a separate set defined for each of the worker processes. By default, worker processes are not bound to any specific CPUs.

For example,

worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
binds each worker process to a separate CPU, while

worker_processes 2;
worker_cpu_affinity 0101 1010;
binds the first worker process to CPU0/CPU2, and the second worker process to CPU1/CPU3. The second example is suitable for hyper-threading.

The special value auto (1.9.10) allows binding worker processes automatically to available CPUs:

worker_processes auto;
worker_cpu_affinity auto;
The optional mask parameter can be used to limit the CPUs available for automatic binding:

worker_cpu_affinity auto 01010101;
The directive is only available on FreeBSD and Linux.

相关模块
worker_processes定义NGINX运行调用多少个CPU核心(worker)

worker_processes auto;

具体作用参考官方文档,不做过多概述
Syntax: worker_processes number | auto;
Default:
worker_processes 1;
Context: main
Defines the number of worker processes.

The optimal value depends on many factors including (but not limited to) the number of CPU cores, the number of hard disk drives that store data, and load pattern. When one is in doubt, setting it to the number of available CPU cores would be a good start (the value “auto” will try to autodetect it).

The auto parameter is supported starting from versions 1.3.8 and 1.2.5.

NGINX worker进程优先级优化

worker_priority可以定义NGINX的worker进程在系统中运行的nice值(运行优先级)

worker_priority numbe

附:准确来说nice值并不是linux系统中的优先级,真正的优先级是PRI,但是nice和PRI的关系是这样PRI(new)=PRI(old)+nice,也就是说nice值是可以直接影响到优先级的~!so~网上有部分文档直接把nice叫做优先级不算是错,我们知道这里有这个点就行了。ps命令显示的PRI值越大进程的优先级越高~!nice值越小优先级越高。

具体作用参考官方文档,不做过多概述
Syntax: worker_priority number;
Default:
worker_priority 0;
Context: main
Defines the scheduling priority for worker processes like it is done by the nice command: a negative number means higher priority. Allowed range normally varies from -20 to 20.

Example:

worker_priority -10;

NGINX最大连接数限制

worker_rlimit_nofile 能够限制NGINX全部的worker最大的连接数(并发数)

worker_rlimit_nofile number

具体作用参考官方文档,不做过多概述
Syntax: worker_rlimit_nofile number;
Default: —
Context: main
Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes. Used to increase the limit without restarting the main process.

相关命令

此处内容需要评论回复后(审核通过)方可阅读。

Last modification:January 28th, 2019 at 10:26 pm
如果觉得我的文章对你有用,请随意赞赏

2 comments

  1. 看一下

    看一下

  2. 813840770

    qwewqe

Leave a Comment