PHP acceleration is a performance boosting method based on caching PHP scripts in a compiled state to avoid parsing and compiling the source code on every request. Caching inside the shared memory is the essential part of total acceleration concept which is also the leading fact for an optimum result. A well-built acceleration shall reduce server load while increasing the speed from 1 to 10 times.
.
.
If we put hardware efficiency aside and focus on application issues, acceleration success depends on many factors such as server type (apache, lighttpd, …), inherent execution time of PHP scripts, coding quality, CMS type (if being used). Therefore we can’t precisely state that one accelerator would beat another especially on the basis of benchmarks published over this subject. In this article we’ll substantially address shared memory side of the matter while deploying eAccelerator 0.9.5.3 release over PHP5 on FreeBSD 8.0-RELEASE-p1. The latest release, 0.9.6, supports PHP 5.3, PHP 5.2 and 5.1.
I recommend you to update your ports directory before moving on.
# portsnap fetch # portsnap update
First let’s check concerned packages;
# php -v PHP 5.2.11 with Suhosin-Patch 0.9.7 (cli) (built: Dec 29 2009 18:28:11) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
# apachectl -v Server version: Apache/2.2.14 (FreeBSD) Server built: Dec 29 2009 15:39:28
To stick with the installation, we visit the eAccelerator directory inside ports collection;
# cd /usr/ports/www/eaccelerator # make install clean
In order to configure and load eAccelerator either as Zend extension or a PHP extension, we have to edit php.ini file and insert the appropriate lines. If you prefer to run as PHP extension, you’ll call it by extension=”eaccelerator.so”. I prefer to employ it as Zend extension, therefore I’ll designate the full path to the eaccelerator.so library;
# vi /usr/local/etc/php.ini
;---------------------- eAccelerator --------------------- zend_extension="/usr/local/lib/php/20060613/eaccelerator.so" eaccelerator.shm_size="16" eaccelerator.cache_dir="/tmp/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="0" eaccelerator.shm_prune_period="0" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" ;----------------------------------------------------------
Before putting eAccelerator into service, we’ll dwell upon the shared memory issue which is the essential part of the acceleration and our topic.
eaccelerator.shm_size=”16″ setting will allow you to control the amount of shared memory in megabytes that eAccelerator shall allocate to cache PHP scripts. Value “0″ will use the default size. By default, FreeBSD and mostly other *NIX types usually have too little shared memory available for an accelerator to be effective. On FreeBSD, the maximum amount of memory a process can allocate is limited by the number set by kern.ipc.shmmax (kern.ipc.shmmax: Maximum shared memory segment size, IPC=inter-process communication) kernel configuration parameter. If you allocate more than this value, eAccelerator may fail to initialize. For optimal performance of the accelerator, you have to play with this parameter and calibrate eaccelerator.shm_size accordingly for best practice. You may evaluate and increase the shmmax value to utmost the amount of physical memory especially if you’re running database or additional java applications on the same server. Note that FreeBSD 7.2+ can use shared memory > 2Gb (kern.ipc.shmmax=2147483648).
Now let’s check the default value on FreeBSD 8.0 indeed which depends on the setup;
# sysctl -a | grep shmmax kern.ipc.shmmax: 33554432
The size in above parameter is given in bytes which is default 32 MB. As this parameter is a part of an equation, when we want to expand it further we have to set another parameter; kern.ipc.shmall (Maximum number of pages available for shared memory) appropriately.
kern.ipc.shmall = kern.ipc.shmmax / hw.pagesize
Default value of ipc.shmall can be seen by the command below;
# sysctl -a | grep shmall kern.ipc.shmall: 8192
What is the value of our hw.pagesize then ?
# sysctl -a | grep hw.pagesize hw.pagesize: 4096
Considering the equation above, we may set the shmall to the value of kern.ipc.shmmax divided by the hardware page size. For instance if we want 512 MB. of shared memory, we’ll set kern.ipc.shmmax=536870912 and kern.ipc.shmall=131072 in bytes.
( 131072 = 536870912 / 4096 )
To change and evaluate the new settings on run time;
# sysctl -w kern.ipc.shmmax=536870912 kern.ipc.shmmax: 33554432 -> 536870912
# sysctl -w kern.ipc.shmall=131072 kern.ipc.shmall: 8192 -> 131072
As PHP and furthermore MySQL performance depends on various kernel tuning parameters which effects each other in one way or another, on the prompting of eaccelerator integration you can start building your own sysctl.conf to experiment the effects of different values by raising and reducing them on small scales. After observing and making sure that stability and efficiency of your server applications progress, you can have these settings persist over system reboot by inserting the parameters directly into /etc/sysctl.conf
kern.ipc.shmmax=536870912
kern.ipc.shmall=131072
Let’s turn back to eAccelerator configuration and set eaccelerator.shm_size=”256″
By default eAccelerator uses disk space in addition to shared memory for caching scripts. Consequently, we’ll create this cache directory inside /tmp and set its permissions to make it writable for the user eAccelerator runs under;
# mkdir /tmp/eaccelerator # chown www /tmp/eaccelerator # chmod 0644 /tmp/eaccelerator
Restart your webserver to initialize eAccelerator;
# apachectl restart
Let’s check whether it has been initialized;
# php -v PHP 5.2.11 with Suhosin-Patch 0.9.7 (cli) (built: Dec 29 2009 18:28:11) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
If it’s successfully loaded, subdirectories and cached scripts appear in the cache directory;
# cd /tmp/eaccelerator/1/1/ # ls -al -rw------- 1 www wheel 11376 Mar 9 18:29 eaccelerator-101.20312741 -rw------- 1 www wheel 28760 Mar 9 18:29 eaccelerator-101.30312741 -rw------- 1 www wheel 17400 Mar 9 18:29 eaccelerator-101.40312741 -rw------- 1 www wheel 3168 Mar 9 18:29 eaccelerator-101.50312741 -rw------- 1 www wheel 124952 Mar 9 18:29 eaccelerator-101.89212741
Alternatively when you prepare and execute a test.php in your webroot with the simple content below, you’ll notice that a separate section within PHP info page will be created for eAccelerator showing pretty enough information concerning the amount of allocated memory, number of cached scripts, configuration directives and values etc.
<?php phpinfo(); ?>

Finally I won’t recommend you to turn on logging option except for debugging purposes. Further configuration options can be found at http://www.eaccelerator.net/wiki/Settings







RSS feed for comments on this post.




