Home  >  Article  >  System Tutorial  >  Record once and use strace to diagnose the problem of PHP occupying too much system resources.

Record once and use strace to diagnose the problem of PHP occupying too much system resources.

WBOY
WBOYforward
2024-05-03 16:31:14962browse

Local environment: redhat6.7 system. nginx1.12.1, php7.1.0, the code uses the yii2 framework

Question: The local web site needs to use the elasticsearch service. When PHP uses elasticsearch built on a local server, the local load is normal. When I use AWS's elasticsearch service, the load on the local server is often too high. Check the nginx and php logs and find no exceptions. The number of concurrent connections in the system is also not high. At this time, I thought of a strace diagnostic tool that our boss told me.

Debugging process:

  • Find a php child process id
  • strace -cp pid traces process calls

System load at that time:

Record once and use strace to diagnose the problem of PHP occupying too much system resources.

strace debugging process

Record once and use strace to diagnose the problem of PHP occupying too much system resources.

Here we find that when php calls elasticsearch, it will look for a file locally, and this file does not exist. This results in high server load. By comparing the difference between aws elasticsearch and local es cluster. I found that only the calling method was different. The code is called using the https method, so it will look for the certificate library file locally. I immediately contacted the development team and changed the calling method to http. After observing for a period of time, the server load returned to normal.

strace -T -e access -p 1379

Record once and use strace to diagnose the problem of PHP occupying too much system resources.

The above is the detailed content of Record once and use strace to diagnose the problem of PHP occupying too much system resources.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete