Apache-using php in embedded devices, php-fpm occupies a high CPU

Source: Internet
Author: User
Tags apc
At present, there is a project on hand, which is to run a website on an embedded device with a linux system. The CPU of the device is in the RAM structure, with a single core and 1 GB. We set up Apache + Mysql + php in the system, and then write a website to run it. It seems like a vro. At present, there is a project on hand that runs a website on an embedded device with a linux system.

The CPU of the device is in the RAM structure, with a single core and 1 GB.

We set up Apache + Mysql + php in the system, and then write a website to run it. It seems a bit similar to the web page setting program in the vro, but we are a complete website application.

Php runs slowly on the device, but the access speed is improved by merging php files (reducing IO) and using apc (caching opcode and some data and pages.

However, every time you access a website on the device, the cpu usage of the php-fpm can instantly occupy about 40%. If you do not access the page, the cpu usage will decrease. Because the device also runs other services and programs, when php-fpm occupies too much cpu, it will cause problems with other programs.

Why does php-fpm occupy so many CPUs? Apache does not account for much. Is there a way to reduce the cpu.

I have thought about using some embedded web servers, but I feel that cpu usage is not a problem of apache, but a problem of php and I don't know how to deal with it. Do you have any suggestions or ideas?

PS: Only one user can access the website on the device.

Reply content:

At present, there is a project on hand, which is to run a website on an embedded device with a linux system.

The CPU of the device is in the RAM structure, with a single core and 1 GB.

We set up Apache + Mysql + php in the system, and then write a website to run it. It seems a bit similar to the web page setting program in the vro, but we are a complete website application.

Php runs slowly on the device, but the access speed is improved by merging php files (reducing IO) and using apc (caching opcode and some data and pages.

However, every time you access a website on the device, the cpu usage of the php-fpm can instantly occupy about 40%. If you do not access the page, the cpu usage will decrease. Because the device also runs other services and programs, when php-fpm occupies too much cpu, it will cause problems with other programs.

Why does php-fpm occupy so many CPUs? Apache does not account for much. Is there a way to reduce the cpu.

I have thought about using some embedded web servers, but I feel that cpu usage is not a problem of apache, but a problem of php and I don't know how to deal with it. Do you have any suggestions or ideas?

PS: Only one user can access the website on the device.

If apache, mysql, and php are all crowded into an embedded device, it is likely that the memory is insufficient or the cache space is occupied, resulting in a large number of page faults triggered every access.

Another possibility is that the pm is set to ondemand or another non-fixed algorithm, allowing php-fpm to take time to start new php processes.

If I remember correctly, after the PHP-FPM receives the request, it will cyclically find the next idle worker in the worker list by default, instead of reusing the old one. If you have enabled 10 workers, the new worker may have switched out the memory.

We recommend that you reduce the number of workers for php-fpm spawn. For single-core processors, mysql is deployed on the same device, and even one worker is enough. (When I/O is not needed, opening more workers is just to divide the CPU occupied by 100% long ago, and creates unnecessary context switches .)

We recommend that you use mod_php directly for embedded systems using apache + php. If possible, lighttpd + php-fcgi should be faster.

Related Article

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.