NYCPHP Meetup

NYPHP.org

Fwd: Re: [PHP-DEV] Benchmarking 4.3.2 vs 4.1.2

Hans Zaunere zaunere at yahoo.com
Wed Jun 4 12:36:14 EDT 2003


Knowing how performance hungry we all are, some useful info and performance
tips below.


--- Rasmus Lerdorf <rasmus at lerdorf.com> wrote:
> Date: Wed, 4 Jun 2003 09:21:55 -0700 (PDT)
> From: Rasmus Lerdorf <rasmus at lerdorf.com>
> To: Jeff Moore <jeff at procata.com>
> CC: internals at lists.php.net
> Subject: Re: [PHP-DEV] Benchmarking 4.3.2 vs 4.1.2
> 
> Uh, the number of open() calls really shouldn't change.  Are you sure you
> are comparing the same code?  And how are you testing?  Attach strace or
> truss to your running httpd process and hit your script a single time.
> Then look at the output and compare them.  Some of the keys to reducing
> syscalls:
> 
>   - don't use open_basedir or safe_mode restrictions
>   - always include/require files by their absolute paths (./foo.inc is ok)
>   - if you have to use include_path includes, make sure the dir you
>     hit most often is first in the include_path (even before .)
>   - optimize your code.  ie. don't use while(!feof($fp)) to loop through
>     a file, check the return of your fgets() instead, for example.
> 
> In your example, you can of course replace your code with a single call to
> file_get_contents() which is a new function in 4.3 and should
> significantly reduce your syscall overhead.
> 
> 4.3.3 will have Sascha's fd-patch which gets rid of a stat() call
> associated with every file open, so if you are really keen on reducing
> your syscalls even further, you can grab a snapshot.
> 
> I also have some hacks we use here at Yahoo that eliminate a bunch of
> other calls, but they aren't exactly generic in that they break various
> aspects of PHP that in my controlled environment here I am fine with.  I
> have been pondering whether to add some sort of --broken-but-fast compile
> switch an commit those changes, but it would likely cause a whole lot of
> confusion.
> 
> -Rasmus
> 
> On Wed, 4 Jun 2003, Jeff Moore wrote:
> 
> > I remember a discussion about system calls here earlier.  What is the
> > status of that?
> >
> > I've been doing some tests and have found that this code runs about 2.5
> > times slower under 4.3.2 than it did on 4.1.2 on the same machine
> > (running OS X):
> >
> > <?php
> > $filename = 'file.html';
> > $fd = fopen($filename, 'rb');
> > $content = fread($fd, filesize($filename));
> > fclose($fd);
> > echo $content;
> > ?>
> >
> > I did some tests with fs_usage to check file system calls and found
> > that for a zero length test.php file, 4.3.2 makes the following
> > additional calls beyond 4.1.2:
> >
> > 1 chdir  /Library/WebServer/Documents/rot/bench
> > 1 fchdir
> > 12 fstat
> > 5 fstatfs
> > 5 getdirentries
> > 7 lseek O=0x00000000
> > 1 lstat test.php
> > 6 lstat (., .., ../.., etc.
> > 6 open  (., .., ../.., etc)
> > 1 stat
> >
> > The fread example above made the following additional calls in 4.3.2
> > beyond 4.1.2:
> >
> > 2 chdir /Library/WebServer/Documents/rot/bench
> > 2 fchdir
> > 32 fstat
> > 15 fstatfs
> > 15 getdirentries
> > 16 lseek O=0x00000000
> > 1 lstat  file.html
> > 1 lstat test.php
> > 18 lstat (., .., ../.., etc.)
> > 17 open  (., .., ../.., etc)
> > 4 stat
> > 1 stat .
> >
> > some of my counts my be slightly off - I counted them by hand.
> >
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
> 




More information about the talk mailing list