linux nginx cpu 高,Linux 系统 Nginx性能优化CPU参数

Nginx性能优化CPU参数worker_cpu_affinity使用说明

官方说明:

worker_cpu_affinity

Syntax:worker_cpu_affinity cpumask [cpumask...]

Default:none

Linux only.

With this option you can bind the worker process to a CPU, it

calls sched_setaffinity().

For example,

worker_processes 4;

worker_cpu_affinity 0001 0010 0100 1000;

Bind each worker process to one CPU only.

worker_processes 2;

worker_cpu_affinity 0101 1010;

Bind the first worker to CPU0/CPU2, bind the second worker to

CPU1/CPU3. This is suitable for HTT.

一个服务器为Q9300单cpu,4核心,于是可以直接用官方的配置:worker_cpu_affinity 0001 0010

0100 1000;

效果如下,看起来每个cpu核心都比较平均:

top - 21:17:56 up 4 days, 7:41, 3 users, load average: 0.25,

0.44, 0.47

Tasks: 238 total, 1 running, 237 sleeping, 0 stopped, 0

zombie

Cpu0 : 0.3%us, 0.3%sy, 0.0%ni, 94.2%id, 5.2%wa, 0.0%hi, 0.0%si,

0.0%st

Cpu1 : 0.3%us, 0.0%sy, 0.0%ni, 96.2%id, 0.6%wa, 0.6%hi, 2.2%si,

0.0%st

Cpu2 : 0.3%us, 0.0%sy, 0.0%ni, 93.5%id, 5.5%wa, 0.0%hi, 0.6%si,

0.0%st

Cpu3 : 0.0%us, 0.0%sy, 0.0%ni, 96.5%id, 3.5%wa, 0.0%hi, 0.0%si,

0.0%st

Mem: 8119372k total, 3641940k used, 4477432k free, 504900k

buffers

Swap: 8385888k total, 10664k used, 8375224k free, 2407512k

cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

30743 apache 20 0 6632 3800 812 S 0.3 0.0 0:00.51 nginx

30745 apache 20 0 7156 4384 812 S 0.3 0.1 0:00.85 nginx

以下文字来源于:http://www.chengyongxu.com/blog/nginx的worker_cpu_affinity详解/

配置文件中的worker_cpu_affinity可以用来绑定每个nginx进程所使用的CPU

官方的解释是:

#----------------------------引用文字-开始----------------------------

Syntax: worker_cpu_affinity cpumask [cpumask...]

Default: none

Linux only.

With this option you can bind the worker process to a CPU, it calls

sched_setaffinity().

For example,

worker_processes 4;

worker_cpu_affinity 0001 0010 0100 1000;

Bind each worker process to one CPU only.

worker_processes 2;

worker_cpu_affinity 0101 1010;

Bind the first worker to CPU0/CPU2, bind the second worker to

CPU1/CPU3. This is suitable for HTT.

#----------------------------引用文字-结束----------------------------

最关键的地方没说清楚,怎样来表示每个CPU?

经过漫天的搜索和多次尝试发现

a4c26d1e5885305701be709a3d33442f.png

那么,16核的cpu每个进程分配到一个cpu就应该是

a4c26d1e5885305701be709a3d33442f.png

测试一下,用别的服务器发出大量请求

ab -n 20000 -k http://您的ip或域名/index.php

在被测试的服务器上查看cpu状态

top

然后按1

a4c26d1e5885305701be709a3d33442f.png

可以看到每个cpu都在工作了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值