View Issue Details

IDProjectCategoryView StatusLast Update
0001658XdebugUncategorizedpublic2019-07-19 11:39
Reporterclewis2019 Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
Product Version2.7.0 
Summary0001658: Very slow performance when xdebug extension is loaded, but not enabled
DescriptionRunning simple php benchmark script, http://www.php-benchmark-script.com, which just loops over a series of string and math operations with php 7.0, 7.1, or 7.3, results in execution time being 6-7 times slower than without the extension loaded. This is on a centos 7 system.

strace -c shows:

% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
 90.93 0.239892 10 25066 gettimeofday
  3.21 0.008480 13 678 21 stat
  1.21 0.003205 10 308 mmap
  0.79 0.002089 10 204 mprotect
  0.69 0.001820 10 183 close
 
without xdebug loaded:

% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
 34.58 0.010055 15 677 20 stat
 14.02 0.004075 13 305 mmap
  9.18 0.002669 13 202 mprotect
  8.52 0.002476 15 161 4 open
  7.66 0.002228 12 182 close
  6.67 0.001940 12 165 fstat
  4.77 0.001386 10 138 munmap
  4.57 0.001330 12 110 read
  2.35 0.000684 15 47 3 lseek
  2.18 0.000635 14 44 getdents
  2.16 0.000628 15 43 43 ioctl
  1.23 0.000357 16 22 openat
  0.42 0.000121 15 8 3 lstat
  0.37 0.000108 3 31 brk
  0.22 0.000064 13 5 3 access
  0.22 0.000063 6 11 write
  0.21 0.000062 31 2 statfs
  0.17 0.000048 10 5 rt_sigaction
  0.09 0.000026 3 9 gettimeofday
  0.07 0.000021 11 2 rt_sigprocmask

/etc/php.d/xdebug.ini:

;zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_autostart=0
xdebug.remote_enable=0
xdebug.profiler_enable=0
xdebug.default_enable=0
xdebug.profiler_enable_trigger = off

Steps To Reproducerun attached script with or without xdebug extension enabled:

Additional InformationI was expecting that with xdebug loaded, but not triggered, the performance would be roughly the same as with it not loaded, but that is not what I have experienced.
Tagsperformance
Operating Systemlin
PHP Version7.0.20-7.0.24

Activities

clewis2019

2019-04-21 14:48

reporter  

bench.php (3,175 bytes)   
<pre>
<?php
/*
##########################################################################
#                      PHP Benchmark Performance Script                  #
#                         � 2010 Code24 BV                               # 
#                                                                        #
#  Author      : Alessandro Torrisi                                      #
#  Company     : Code24 BV, The Netherlands                              #
#  Date        : July 31, 2010                                           #
#  version     : 1.0                                                     #
#  License     : Creative Commons CC-BY license                          #
#  Website     : http://www.php-benchmark-script.com                     #	
#                                                                        #
##########################################################################
*/

	function test_Math($count = 1000) {
		$time_start = microtime(true);
		$mathFunctions = array("abs", "acos", "asin", "atan", "bindec", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt");
		foreach ($mathFunctions as $key => $function) {
			if (!function_exists($function)) unset($mathFunctions[$key]);
		}
		for ($i=0; $i < $count; $i++) {
			foreach ($mathFunctions as $function) {
				$r = call_user_func_array($function, array($i));
			}
		}
		return number_format(microtime(true) - $time_start, 3);
	}
	
	
	function test_StringManipulation($count = 1000) {
		$time_start = microtime(true);
		$stringFunctions = array("addslashes", "chunk_split", "metaphone", "strip_tags", "md5", "sha1", "strtoupper", "strtolower", "strrev", "strlen", "soundex", "ord");
		foreach ($stringFunctions as $key => $function) {
			if (!function_exists($function)) unset($stringFunctions[$key]);
		}
		$string = "the quick brown fox jumps over the lazy dog";
		for ($i=0; $i < $count; $i++) {
			foreach ($stringFunctions as $function) {
				$r = call_user_func_array($function, array($string));
			}
		}
		return number_format(microtime(true) - $time_start, 3);
	}


	function test_Loops($count = 1000) {
		$time_start = microtime(true);
		for($i = 0; $i < $count; ++$i);
		$i = 0; while($i < $count) ++$i;
		return number_format(microtime(true) - $time_start, 3);
	}

	
	function test_IfElse($count = 1000) {
		$time_start = microtime(true);
		for ($i=0; $i < $count; $i++) {
			if ($i == -1) {
			} elseif ($i == -2) {
			} else if ($i == -3) {
			}
		}
		return number_format(microtime(true) - $time_start, 3);
	}	
	
	
	$total = 0;
	$functions = get_defined_functions();
	$line = str_pad("-",38,"-");
	echo "<pre>$line\n|".str_pad("PHP BENCHMARK SCRIPT",36," ",STR_PAD_BOTH)."|\n$line\nStart : ".date("Y-m-d H:i:s")."\nServer : {$_SERVER['SERVER_NAME']}@{$_SERVER['SERVER_ADDR']}\nPHP version : ".PHP_VERSION."\nPlatform : ".PHP_OS. "\n$line\n";
	foreach ($functions['user'] as $user) {
		if (preg_match('/^test_/', $user)) {
			$total += $result = $user();
            echo str_pad($user, 25) . " : " . $result ." sec.\n";
        }
	}
	echo str_pad("-", 38, "-") . "\n" . str_pad("Total time:", 25) . " : " . $total ." sec.</pre>";
echo "\n";	
?>
bench.php (3,175 bytes)   

derick

2019-04-21 15:03

administrator   ~0005003

The gettimeofday issue (top of your list), should be fixed in Xdebug 2.7.1: https://bugs.xdebug.org/view.php?id=1641 — Will you please try that?

Besides that, Xdebug does have quite a bit of overhead, even it's enabled. I hope to fix that in Xdebug 3.0, as outline at https://derickrethans.nl/xdebug-experience.html

clewis2019

2019-04-21 21:16

reporter   ~0005005

I followed your suggestion and compiled the 2.7.1 version, but did not see any improvement: the overall performance was still about 6 times slower.

The number of gettimeofday did not change.

% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
 90.81 0.248393 10 25066 gettimeofday

huguesalary

2019-07-18 00:07

reporter   ~0005068

I am also running into this issue.

I was using PHP 7.0 with xdebug 2.5.0 with no slowness when the extension was loaded and not enabled, but now, using PHP 7.3 with xdebug 2.7.1 and 2.7.2 (the 2 versions I tried) my application becomes extremely slow.

I originally reported this issue here https://bugs.xdebug.org/view.php?id=1685 thinking I was running into another problem.

derick

2019-07-19 11:39

administrator   ~0005073

I am closing out this issue, as there is no actionable issue here. I am reviewing Xdebug's performance for Xdebug 3.0.

Issue History

Date Modified Username Field Change
2019-04-21 14:48 clewis2019 New Issue
2019-04-21 14:48 clewis2019 Tag Attached: performance
2019-04-21 14:48 clewis2019 File Added: bench.php
2019-04-21 15:03 derick Assigned To => derick
2019-04-21 15:03 derick Status new => feedback
2019-04-21 15:03 derick Note Added: 0005003
2019-04-21 21:16 clewis2019 Note Added: 0005005
2019-04-21 21:16 clewis2019 Status feedback => assigned
2019-07-18 00:07 huguesalary Note Added: 0005068
2019-07-19 11:39 derick Status assigned => resolved
2019-07-19 11:39 derick Resolution open => no change required
2019-07-19 11:39 derick Note Added: 0005073
2020-03-12 16:35 derick Category Usage problems (Wrong Results) => Variable Display
2020-03-12 16:38 derick Category Variable Display => Uncategorized