Reasons why a php process cpu % nice is very high

Source: Internet
Author: User
1. symptom Description: 1. the CPU usage of % user and % sys is not high, but % nice occupies a large amount of CPU resources, with a maximum CPU usage of more than 60%; 2. In ps-elf, PRI is 90, NI is 10, and top is 30 and NI10. Question: Why is the priority value in ps different from that in top? PR in top is: Thepriorityofthe

1. symptom Description: 1. the CPU usage of % user and % sys is not high, but % nice occupies a large amount of CPU resources, with a maximum CPU usage of more than 60%; 2. In ps-elf, the PRI value is 90, the NI value is 10, and the top value is 30 and NI 10. Question: Why are the priority values in ps different from those in top? PR in top is: The priority of

1. symptom description:

1. CPU usage of % user and % sys is not high, but % nice occupies a large amount of CPU resources, with a maximum CPU usage of more than 60%; 2. In ps-elf, PRI is 90, NI is 10, and prvalue is 30 and NI 10 is displayed on top;

Problem:Why is the priority value in ps different from that in top?
PR in top is: The priority of the task (value range:-20 Highest, 19 lowest)
In ps, PRI is: realtime priority (calculated based on nice () and setpriority (). The Static priority value is 1-99, and Dynamic priority has not been understood yet)

3. sar information collection

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 %idle12:01:01 AM all 0.39 26.67 1.84 30.15 0.00 40.9512:02:03 AM all 0.30 24.07 2.74 30.10 0.00 42.8012:03:01 AM all 0.27 23.61 1.65 34.48 0.00 40.0012:04:02 AM all 0.26 23.37 1.96 34.87 0.00 39.5412:05:04 AM all 0.31 24.08 3.74 36.66 0.00 35.2112:06:02 AM all 0.43 21.96 2.09 34.93 0.00 40.5912:07:16 AM all 0.25 23.66 2.07 59.63 0.00 14.3812:08:02 AM all 0.33 30.21 2.01 36.88 0.00 30.57

Ii. server hardware/software:

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

Iii. problem determination:
1. NICE resources are generally generated by user-side control;
2. Unless a large number of sleep functions are used in the program or nice functions are called, the user-defined priority level is given, but the general program will not be so abnormal;

4. troubleshooting process:
1. Traditionally, it is a problem of program development. It is a waste of time to find words like sleep and nice in the code;
2. ps-elf | grep master, found that the startup time of php-fpm is inconsistent, some are, some are. If it is defined by crontab, the time will certainly not be so inconsistent;
3. Search for/etc/crontab. No scheduled task is defined in the file;
4. The scheduled task of RHEL6 is taken over by anacrontab. anacrontab is a supplement to crontab. The content is as follows: (The problem lies in the red + note line below)

# Cat/etc/anacrontab #/etc/anacrontab: configuration file for anacron # See anacron (8) and anacrontab (5) for details. SHELL =/bin/shPATH =/sbin:/bin:/usr/sbin: /usr/binMAILTO = root # the maximal random delay added to the base delay of the jobsRANDOM_DELAY = 45 # the jobs will be started during the following hours onlySTART_HOURS_RANGE = 3-22 # period in days delay in minutes job-identifier command1 5 cron. daily nice run-parts/etc/cron. daily # log cutting timing task in this 7 25 cron. weekly nice run-parts/etc/cron. weekly @ monthly 45 cron. monthly nice run-parts/etc/cron. monthly

5. Thinking and optimization:
1. It is not recommended to use anacrontab on the server and continue to use crontab; (this problem does not exist in RHEL5 );
2. In fact, the use of nice commands by anacrontab does not cause any problems, mainly because it works with restart in the php-fpm STARTUP script;
3. If php-fpm uses reload or kill-USR2, nice does not take effect, and the priority level of the original PID is used. Because we certainly won't bring nice when starting php-fpm manually.

Original article address: explanation of the reason why the cpu % nice of a php process is very high. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.