Home php教程 php手册 一个php进程cpu %nice很高的原因详解

一个php进程cpu %nice很高的原因详解

Jun 06, 2016 pm 08:13 PM
cpu php reason now Detailed explanation process High

一、 现象描述: 1、 CPU的%user、%sys占用的CPU不高,但%nice占用了大量的CPU资源,最高占用CPU的60%以上;2、 ps -elf中PRI为90,NI为10,top看到PR值为30,NI 10; 问题: 为什么从ps中看到的priority值和top中的不同? top中的PR是:The priority of the

一、 现象描述:

1、 CPU的%user、%sys占用的CPU不高,但%nice占用了大量的CPU资源,最高占用CPU的60%以上;
2、 ps -elf中PRI为90,NI为10,top看到PR值为30,NI 10;
Copy after login

问题:为什么从ps中看到的priority值和top中的不同?
top中的PR是:The priority of the task(取值范围:-20最高,19最低)
ps中的PRI是:realtime priority(根据 nice( ) 和setpriority( ) 计算,Static priority 取值1-99,Dynamic priority还没有看懂)

3、sar信息收集

CPU:
Linux 2.6.32-279.el6.x86_64 (web2.17173ops.com) 05/09/2014 _x86_64_ (8 CPU)
12:00:04 AM CPU %user %nice %system %iowait %steal %idle
12:01:01 AM all 0.39 26.67 1.84 30.15 0.00 40.95
12:02:03 AM all 0.30 24.07 2.74 30.10 0.00 42.80
12:03:01 AM all 0.27 23.61 1.65 34.48 0.00 40.00
12:04:02 AM all 0.26 23.37 1.96 34.87 0.00 39.54
12:05:04 AM all 0.31 24.08 3.74 36.66 0.00 35.21
12:06:02 AM all 0.43 21.96 2.09 34.93 0.00 40.59
12:07:16 AM all 0.25 23.66 2.07 59.63 0.00 14.38
12:08:02 AM all 0.33 30.21 2.01 36.88 0.00 30.57
Copy after login

二、服务器硬/软件:

Product Name: PowerEdge R410
CPU:Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
Memory:24GB 4*6
OS:Red Hat Enterprise Linux Server release 6.3 (Santiago)
Web server:nginx version: nginx/1.4.4
CGI server:php-5.3.21
Copy after login

三、 判断问题:
1、 NICE资源一般是用户端控制的行为产生;
2、 除非程序中有大量的使用sleep,或者是调用了nice等函数,对自定义了优先级别,但一般程序不会这么变态;

四、 查找问题过程:
1、习惯性认为是程序开发的问题,在代码中不断查找类似sleep、nice的字眼,浪费了一些时间;
2、ps -elf | grep master,发现php-fpm启动时间不一致,有的是03:57,有的是4:03,如果是crontab定义的,时间肯定不会这么不一致;
3、查找/etc/crontab,文件里面没有定义任何定时任务;
4、RHEL6的定时任务被anacrontab接管,anacrontab是crontab的补充,内容如下:(问题也就出在下面红色+备注的那行)

# cat /etc/anacrontab 
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily ## 日志切割定时任务在此
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
Copy after login

五、 思考、优化:
1、不建议在服务器上使用anacrontab,继续使用crontab;(RHEL5不存在此问题);
2、其实anacrontab使用nice指令也不会出现问题,主要是和php-fpm启动脚本中的restart配合导致这种情况的发生;
3、php-fpm使用reload或者是kill -USR2,nice都不会生效,会按原PID的优先等级。因为手工启动php-fpm时我们肯定不会带上nice。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles