PHP garbage collector statistics

I am doing some PHP memory tests, and I would like to get garbage collector statistics.

I followed this guide in an white paper: http://www.php.net/manual/en/features.gc.performance-considerations.php

I reproduced the exact procedure described by recompiling PHP with this CFLAGS environment variable:

export CFLAGS=-DGC_BENCH=1 ./config.nice make clean make make install 

I did this with PHP 5.3.9: http://fr.php.net/get/php-5.3.9.tar.bz2/from/a/mirror on Debian Squeeze 6.0.4 64 bit.

Then I tried to execute a sample script on the command line, they provide php gc.php :

 <?php class Foo { public $var = '3.1415962654'; } for ( $i = 0; $i <= 1000000; $i++ ) { $a = new Foo; $a->self = $a; } echo memory_get_peak_usage(), "\n"; ?> 

As they said, this should be displayed at the end of the script, additional gc features, for example:

 GC Statistics ------------- Runs: 110 Collected: 2072204 Root buffer length: 0 Root buffer peak: 10000 Possible Remove from Marked Root Buffered buffer grey -------- -------- ----------- ------ ZVAL 7175487 1491291 1241690 3611871 ZOBJ 28506264 1527980 677581 1025731 

The fact is that these gc statistics are not displayed. It seems that compiling PHP with this CFLAGS did nothing.

Did I miss something?

+4
source share
1 answer

I am going to persuade here, since I did not confirm this, but after reading the text of the GC link that you provided, I did not get the impression that memory_get_peak_usage() should return additional information based on the PHP compilation with the DGC_BENCH flag. The manual says that it returns int, so I suspect that it always returns int.

What he will say, however:

When you run the above code again using the newly created PHP binary, you will see what is shown after PHP has finished executing:

It is not very clear, but I have the impression that additional data GC are printed on stdout or stderr , instead of returning to memory_get_peak_usage() or printed as an additional output to your PHP script.

Try calling the new PHP executable from the command line and see if the GC information is passed to the console when the script ends.

You can try calling it like this: /path/to/custom/php testfile.php

I'm not sure it makes sense to output this information if you use PHP as an Apache module or FastCGI handler, so I suspect you can see it by calling a script from the console, but I may be completely wrong.

UPDATE:

I checked that the GC_BENCH compilation flag is still active, and it is.

Zend / zend.c


 905 #if GC_BENCH 906 fprintf(stderr, "GC Statistics\n"); 907 fprintf(stderr, "-------------\n"); 908 fprintf(stderr, "Runs: %d\n", GC_G(gc_runs)); 909 fprintf(stderr, "Collected: %d\n", GC_G(collected)); 910 fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length)); 911 fprintf(stderr, "Root buffer peak: %d\n\n", GC_G(root_buf_peak)); 912 fprintf(stderr, " Possible Remove from Marked\n"); 913 fprintf(stderr, " Root Buffered buffer grey\n"); 914 fprintf(stderr, " -------- -------- ----------- ------\n"); 915 fprintf(stderr, "ZVAL %8d %8d %9d %8d\n", GC_G(zval_possible_root), GC_G(zval_buffered), GC_G(zval_remove_from_buffer), GC_G(zval_marked_grey)); 916 fprintf(stderr, "ZOBJ %8d %8d %9d %8d\n", GC_G(zobj_possible_root), GC_G(zobj_buffered), GC_G(zobj_remove_from_buffer), GC_G(zobj_marked_grey)); 917 #endif 

Then I compiled PHP 5.3.9 for Apache2 and the CLI. Before deciding to install a test version, I launched a new CLI application for PHP from the console:

 ./sapi/cli/php -v PHP 5.3.9 (cli) (built: Feb 22 2012 19:03:02) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies GC Statistics ------------- Runs: 0 Collected: 0 Root buffer length: 0 Root buffer peak: 7 Possible Remove from Marked Root Buffered buffer grey -------- -------- ----------- ------ ZVAL 15 7 7 0 ZOBJ 0 0 0 0 

It has a GC output, although I did not call PHP. Then I grep'd libphp5.so and saw that it has a bit of GC statistics in it, so I decided to install it live and call from Apache. There is no GC output in the browser, error_log, access_log or any other log files.

Now for the interesting part , I created a test.php file that displays a line and creates frees several variables ...

 root@vm :/php539# php test.php This is a test root@vm :/php539# php < test.php This is a test GC Statistics ------------- Runs: 0 Collected: 0 Root buffer length: 0 Root buffer peak: 7 Possible Remove from Marked Root Buffered buffer grey -------- -------- ----------- ------ ZVAL 16 7 7 0 ZOBJ 0 0 0 0 root@vm :php539# 

Output:

When PHP is compiled with the GC_BENCH parameter, you will not have access to the control information when called from the browser or when parsing PHP files using the -f parameter or passing the file name for parsing. You get control information if you call php interactively or run a script through PHP by reading it from stdin .

+3
source

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


All Articles