PHP: How to run a sampling profiler in production?

Production Environment: Load Balancer / Reverse HTTP Proxy in front of a cluster of work machines with Apache 2.2 with mod_php 5.3 on 64-bit Linux. All working machines have identical fully customizable PHP code and talk about a single PostgreSQL database. The PHP code is optimized in order to spend the processor talking to the database. The database machine has been checked so that there is still plenty of free space.

What I'm looking for: a sampler that can connect to the PHP process using PID and periodically stop the process (for example, using SIGSTOP ), collect the PHP stack through memory checks and continue the process (for example, using SIGCONT ). The stop period should be adjustable, but I think the stop interval should be about 1-10 ms.

It is expected that one PHP process for working machines will always start one request in less than 100 ms. I am most interested in collecting profile data for those processes that take more than 100 ms. The best scenario would be a sampler that will be notified at the beginning of the request, and if the PHP processing process that is processing the request still works after 100 ms, start collecting samples at 1 ms intervals. Thus, any normally working process will be executed to the end without interruptions, and I still get profiles for problem cases.

Does this type of sampler profiler for PHP? . The goal is not to use the tool profiler, because the overhead is too high, and the equipment messed up the statistics (was there, made).

I already know XHProf and Xdebug, but as far as I know, both are instrumental profilers and affect the actual PHP operation codes. I would prefer something that works instead of regular PHP codes.

The closest thing I know will work is to run the PHP code using HipHop and use the sampling proxy for C / C ++ code, but I'm not ready to port the software to HipHop yet. And in this case, the profiling result will be representative only for HipHop, and not for mod_php.

+4
source share
2 answers

Although XHProf does , it adds overhead to the request if it is enabled (via the called function, and not just with the extension enabled), it depends on which flags you use. I measured this recently and found that only XHPROF_FLAGS_MEMORY is the best option for minimal overhead:

http://rpubs.com/msonnabaum/xhprof_overhead

I just run XHProf on a small number of queries like:

 <?php function xhprof_enabled() { if (mt_rand(1, 300) == 1) { xhprof_enable(XHPROF_FLAGS_MEMORY); } } 

But unlike xdebug, just adding an extension doesn't seem to add any overhead.

+2
source

I would not run any profiling tools in a production environment. Testing servers are designed to run profilers and load testing.

0
source

Source: https://habr.com/ru/post/1433526/


All Articles