Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > Calling performance geeks
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 24th May 10:11
rasmus
External User
 
Posts: 1
Default Calling performance geeks



We have a bit of a performance disconnect between 4.4 and 5.1 still. I
was doing some benchmarking today just as a sanity check on some APC
work I have been doing lately and came up with this:

http://lerdorf.com/php/bm.html

You can ignore the apc/eaccelerator stuff. Those numbers are not
surprising. The surprising number to me is how much faster 4.4 still is.

The graph labels are slightly off. The 0, 5 and 10 includes should
really be 1, 6 and 11. The actual benchmark code is here:

http://www.php.net/~rasmus/bm.tar.gz

Tested on a Linux 2.6 Ubuntu box on an AMD chip (syscalls are cheap
there) with current PHP_4_4 and PHP_5_1 checkouts. Was also testing
5.1.2 to see the effect of getting rid of that uncached realpath call.

As far as I can tell auto_globals_jit isn't working at all, but I
eliminated that by doing variables_order = GP for these benchmarks.
Even so, the request_startup is significantly more expensive in 5.1.

Here are callgrind dumps for each. Load them up with kcachegrind and
browse around:

PHP 4.4 http://www.php.net/~rasmus/callgrind.out.1528.gz
PHP 5.1 http://www.php.net/~rasmus/callgrind.out.1488.gz

Each of these is 1000 requests against the top.php and 4top.php scripts.
from bm.tar.gz. If you start at the

The script is trivial and looks like this:

<html>
<?php
$base_dir = '/var/www/bm/';
include $base_dir . 'config.inc';

function top_func($arg) {
$b = $arg.$arg;
echo $b;
}
class top_class {
private $prop;
function __construct($arg) {
$this->prop = $arg;
}
function getProp() {
return $this->prop;
}
function setProp($arg) {
$this->prop = strtolower($arg);
}
}

top_func('foo');
$a = new top_class('bar');
echo $a->getProp();
$a->setProp("AbCdEfG");
echo $a->getProp();
echo <<<EOB
The database is {$config['db']}
and the user is {$config['db_user']}

EOB;
?>
</html>

and config.inc is:

<?php
$config = array(
'db' => 'mysql',
'db_user' => 'www',
'db_pwd' => 'foobar',
'config1' => 123,
'config2' => 456,
'config3' => 789,
'sub1' => array(1,2,3,4,5,6,7,8,9,10),
'sub2' => array("abc","def","ghi","jkl","mno","pqr","stu","v wx","yz")
);
?>

4top.php is identical except for the class definition being PHP 4-style
instead. As in no private and a PHP 4 constructor. Otherwise it is
identical.

I have some ideas for things we can speed up in 5.1. Like, for example,
we should add the ap_add_common_vars() and ap_add_cgi_vars() to the jit
mechanism. There isn't much point filling these in unless the script
tries to get them. the ap_add_common_vars() call is extremely expensive
since it does a qsort with a comparison function that uses strcasecmp.
Of course, this same optimization can be done in 4.4.

If you know your way around kcachegrind, load up the two callgrind files
and see what stands out for you. As far as I can tell, while we can do
some tricks to speed up various helper bits, the slowdown is coming from
the executor trashing its cache lines.

-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote


  sponsored links


2 24th May 10:11
andi
External User
 
Posts: 1
Default Calling performance geeks



What are the results you're getting on an empty script? I'm just
curious whether it's execution speed or startup speed where you are
seeing the big hit. There were changes in both which might have
slowed things down. Another reason to be more careful re: bloat

Anid

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
3 24th May 10:11
rasmus
External User
 
Posts: 1
Default Calling performance geeks


With an empty.php file 0 bytes long I get:

PHP 5.1.3-dev (no opcode cache, variables_order=GP) 1168-1225 req/sec
over 5 runs of 10000 requests each.

PHP 4.4 same config 1897-1951 req/sec

Just to make sure, since in this case an extra header would make a big
difference, the raw headers that came back on both:

HTTP/1.1 200 OK
Date: Mon, 13 Mar 2006 05:31:51 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) PHP/4.4.3-dev
X-Powered-By: PHP/4.4.3-dev
Connection: close
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Mon, 13 Mar 2006 05:35:49 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) PHP/5.1.3RC2-dev
X-Powered-By: PHP/5.1.3RC2-dev
Connection: close
Content-Type: text/html; charset=iso-8859-1

So yes, there are a few characters more, but I checked 5.1.2 as well
which actually has less, and it is about the same speed.

And here are some pretty pictures from kcachegrind since I realize many
don't have the ability to run it. These show an overview of 1000
requests for a 0 byte php file. I start at the whole request and zoom
in on request_startup and then hash_environment on each:

http://www.php.net/~rasmus/bm/php51_empty.png
http://www.php.net/~rasmus/bm/php51_empty_startup.png
http://www.php.net/~rasmus/bm/php51_empty_hash_env.png
http://www.php.net/~rasmus/bm/php44_empty.png
http://www.php.net/~rasmus/bm/php44_empty_startup.png
http://www.php.net/~rasmus/bm/php44_empty_hash_env.png

You will notice things missing from each. Basically kcachegrind is only
showing things that took a significant portion of the execution time, so
for PHP44 you will see much more of the Apache stuff showing up since
the PHP parts were so fast. Here you can see the crazy qsort called
from ap_add_common_vars() if you look at the right side of the
php44_empty.png picture.

The corresponding callgrind raw files are:

http://www.php.net/~rasmus/bm/callgrind.out.2464 PHP 5.1
http://www.php.net/~rasmus/bm/callgrind.out.2548 PHP 4.4

You can load these up in kcachegrind and zoom in on other stuff.

-Rasmus


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
4 24th May 13:43
helly
External User
 
Posts: 1
Default Calling performance geeks


Hello Rasmus,

not a thing for 5.1 or 4.4 but in 5.2 we could change to a case
insensitive comparison function. That would allow us to change nearly
all of strcasecmp to memcmp. And in may cases it means one less
allocation. And it also means a lot of less code. The casinsensitive
comparision is pretty easy because we can use a 256 byte translation
table that can be provided as a static const table. On a X86 systems
we could also provide that in assembler. That would give us the
possibility to use the XLAT instruction that would otherwise not be
used (maybe newer optimizing compiler know about it though).

Maybe it is worse trying to bring it in and checking how much slower
we are getting with it. If the numbers look promising we could go for
the change then.

A word on HEAD/Unicode. If we use a case insensitivity semantics where
only the normal ascii characters are lowercased we can use the same
table based approach.

Anyway from looking at the output the best optimization was brought up by
you already. Using jit for the ap_* stuff.

best regards
marcus


?>>

?>>


Best regards,
Marcus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
5 24th May 13:43
rasmus
External User
 
Posts: 1
Default Calling performance geeks


Well, that doesn't come anywhere near the radar here actually. The
300k+ strcasecmp calls are coming from the qsort in Apache, not from
PHP. Even then, 300k strcasecmp calls is minor here. So I doubt you
could even measure the effect of that change.

-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
6 24th May 13:43
dmitry
External User
 
Posts: 1
Default Calling performance geeks


Hi Rasmus,

I made two improvements in 5.1 and run the same bechmarks on Intel =
Pentium M
1.5GHz 2M cache.

top/top5/top10
=09
php-5.1 740 550 430 req/sec
php-4.4 680 440 290 req/sec

May be the problem is AMD chip?

Thanks. Dmitry.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
7 24th May 13:44
edink
External User
 
Posts: 1
Default Calling performance geeks


I also see very little difference (in favor of php4) on my test box
(Dual Xeon 3.2GHz, running Linux 2.6.12 Fedora Core 3):

php-5.1 (top.php)
plain 3723 req/sec
apc stat=1 6220 req/sec
apc stat=0 6278 req/sec

php-4.4 (4top.php)
plain 3978 req/sec
apc stat=1 6421 req/sec
apc stat=0 6650 req/sec

php-5.1 (top10.php)
plain 1680 req/sec
apc stat=1 3605 req/sec
apc stat=0 3880 req/sec

php-4.4 (4top10.php)
plain 1731 req/sec
apc stat=1 3614 req/sec
apc stat=0 3922 req/sec

Edin


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
8 24th May 13:44
dmitry
External User
 
Posts: 1
Default Calling performance geeks


Have you rebuilt 5.1 HEAD today?

Dmitry.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
9 24th May 13:44
edink
External User
 
Posts: 1
Default Calling performance geeks


Yes, fresh CVS update of 4.4, 5.1 and apc.

Edin

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
10 24th May 17:36
andi
External User
 
Posts: 1
Default Calling performance geeks


Hey,

Thanks for posting this info. It definitely sounds like we should
concentrate on the 0 length script at this point. I saw Dmitry
already made some good improvements.

It'd be helpful if others also run such an empty benchmark because it
seems like the two trees are on par now and that it depends more on
your hardware architecture than the PHP versions.... But if we can
get some more results that would give us a clue. In any case, we can
try and optimize further especially the startup/shutdown routines...
Andi


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666