Apache-using PHP,PHP-FPM in embedded devices consumes very high CPU

Source: Internet
Author: User
Tags apc
Now there is a project on hand that runs a website in an embedded device with a Linux system.

The CPU of the device is RAM structure, single core, 1GB.

We set up a apache+mysql+php in the system and then write a website that runs inside. It feels a bit like the setup of the Web page inside the router, but it's a complete website app.

PHP runs very slowly on the device, but by merging PHP files (reducing IO), using APC (cache opcode and some data and pages), the speed of access is improved.

However, every time you visit the site inside the device, the CPU of PHP-FPM can take up to about 40%, and the CPU consumption will drop when the page is not accessed. Because other services and programs are running on the device, when PHP-FPM consumes too much CPU, it can cause other programs to become problematic.

Why does PHP-FPM occupy so many CPUs? Apache has not accounted for much, there is no way to let the CPU down.

Would have wanted to use some embedded Web server, but feel CPU usage is not the problem of Apache, is the problem of PHP, do not know how to handle. Do you have any suggestions or ideas?

PS: The site in the device has only one user access.

Reply content:

Now there is a project on hand that runs a website in an embedded device with a Linux system.

The CPU of the device is RAM structure, single core, 1GB.

We set up a apache+mysql+php in the system and then write a website that runs inside. It feels a bit like the setup of the Web page inside the router, but it's a complete website app.

PHP runs very slowly on the device, but by merging PHP files (reducing IO), using APC (cache opcode and some data and pages), the speed of access is improved.

However, every time you visit the site inside the device, the CPU of PHP-FPM can take up to about 40%, and the CPU consumption will drop when the page is not accessed. Because other services and programs are running on the device, when PHP-FPM consumes too much CPU, it can cause other programs to become problematic.

Why does PHP-FPM occupy so many CPUs? Apache has not accounted for much, there is no way to let the CPU down.

Would have wanted to use some embedded Web server, but feel CPU usage is not the problem of Apache, is the problem of PHP, do not know how to handle. Do you have any suggestions or ideas?

PS: The site in the device has only one user access.

If apache,mysql,php or anything is crammed into an embedded device, it is likely that there is not enough memory or that the cache space is being squeezed out, causing a large number of page fault to be triggered per visit.

Another possibility is that the PM is set to OnDemand or other non-fixed algorithms, allowing PHP-FPM to constantly take the time to start a new PHP process.

I'm not mistaken, php-fpm. When a request is received, the default is to loop through the worker list to find the next idle worker instead of reusing the old one. If you open 10 workers, the new worker may have swapped out memory.

It is recommended to reduce the number of workers php-fpm spawn. For single-core processors, MySQL is deployed on the same device, and even a worker is enough. (No need for I/O wait, more workers are only to carve up 100% of the CPU occupied already, but also create unnecessary context switch. )

Embedded to use Apache + PHP recommended directly with mod_php. If possible replace LIGHTTPD + php-fcgi should be faster.

  • 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.