Install Eaccelerator PHP cacher to decrease server CPU load on Debian Squeeze GNU / Linux

eaccelerator a php opcode cache optimizer accelerator

I don't know what is happening with Apache but I'm quite disappointed with the poor performance results  of  Apache2.2.16-6+squeeze8  + PHP 5.3.3-7+squeeze14 – installed from Official Debian Squeeze repositories through debs (apache2-mpm-prefork and libapache2-mod-php5). I should say the Apache is mainly processing PHP part of my wordpress blog which of time of writting contains about 1280 posts, few joomla based sites, another little wordpress and few other very little projects written in PHP The daily unique visitors the host gets are not that high about 8000 UNIQUE IP visitors and besides that the machine is equipped with a good amount of memory running on Lenovo PowerEdge host, here is raw system config where I got issues:

System Memory: 8 GB
Dual Core Intel(R) Pentium(R) CPU G630 @ 2.70GHz (5.40 Ghz), with
CPU  cache size    : 3072 KB.

The machine is not too powerful for a server configuration but for about 8000 Unique visitors mostly fetching WordPress pages many of which are cached with W3 Cache WP Plugin and handled back to the client in plain .html it is unusual such Apache CPU overloads happens. It is true the incoming traffic from crawlers puts a high load on the system as some of the WebCrawlers like 80legs sometimes are fetching pages too agressive and therefore create too high loads from PHP code multiple times interpreted by Apache, it is also a fact that sometimes the machines gets a bunch of increased number of requests from normal User IPs, but still the traffic even in peak hours  should not so high to be causing the weird Apache forked childs CPU overloads.

I've used Eacceleartor in the past and it proofed to significantly reduced the load Apache puts on servers CPU on all servers installed . Thus I thought of experimenting and running Eaccelerator on those particular problematic Debian Squeeze host to see if this will make some difference and fully resolve problems or at least reduce the overloads frequency. Whether this weird Apache overloads happens the system load avarage drops often to 80 or 100! The host is completely lagged then and often inaccessible via ssh. The work around is  either manual Apache restart via Apache init script (/etc/init.d/apache2 restart) or be setting a script to automatically restart Apache whether high load is matched. In some cases, the system gets so loaded that even the automated shell script which does restart Apache on high loads is not working, so only fix is to manually do cold system reset.

Eaccelerator though mostly popular among server administrators and thoughmany of the eaccelerators installs are on Debian  as of time of writting in Debian stable Linux does standard repositories does not include it . In past on Debian Lenny I used to  install Eacceleartor using a 3rd party repository but as I tried following my own tutorial to install it from deb without compiling I've figured out eaccelerator .deb's are no longer available.

Thus I proceeded and install it from source, here is how;

1. First to compile eacceleator from source one needs to have installed few build tools

 

 apt-get install --yes php5-dev make

2. Second download it from eaccelerator source repo on github, untar, compile, create eaccelerator cache directory, create eaccelerator config and restart Apache to load new settings.

 cd /usr/local/src

 wget -q https://github.com/eaccelerator/eaccelerator/tarball/master
 mv master eacceleartor.tar.gz

 tar -zxvvf eaccelerator.tar.gz
drwxrwxr-x root/root         0 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/
-rw-rw-r-- root/root       204 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/.gitignore
-rw-rw-r-- root/root       670 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/AUTHORS
-rw-rw-r-- root/root     17992 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/COPYING
-rw-rw-r-- root/root     49163 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/ChangeLog
-rw-rw-r-- root/root       627 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/Makefile.frag
-rw-rw-r-- root/root       269 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/Makefile.in
-rw-rw-r-- root/root      9761 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/NEWS
-rw-rw-r-- root/root     17053 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/PHP_Highlight.php
-rw-rw-r-- root/root      7281 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/README
-rw-rw-r-- root/root      2760 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/README.win32
-rw-rw-r-- root/root      2634 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/bugreport.php
-rw-rw-r-- root/root      9235 2012-08-16 16:34 eaccelerator-eaccelerator-42067ac/config.m4

cd $(ls -ld *eaccel*/|awk '{ print $9 }')  phpize
 ./configure
 make
 make install
 mkdir -p /var/cache/eaccelerator
 chmod 0777 /var/cache/eaccelerator
 cd /etc/php5/conf.d/

echo 'extension="eaccelerator.so"' >>  eaccelerator.ini
echo 'eaccelerator.shm_size="16"' >> eaccelearator.ini
echo 'eaccelerator.cache_dir="/var/cache/eaccelerator"' >> eaccelerator.ini
echo 'eaccelerator.enable="1"' >> eaccelerator.ini
echo 'eaccelerator.optimizer="1"' >> eaccelerator.ini
echo 'eaccelerator.check_mtime="1"' >> eaccelerator.ini
echo 'eaccelerator.debug="0"' >> eaccelerator.ini
echo 'eaccelerator.filter=""' >> eaccelerator.ini
echo 'eaccelerator.shm_max="0"' >> eaccelerator.ini
echo 'eaccelerator.shm_ttl="0"' >> eacceleartor.ini
echo 'eaccelerator.shm_prune_period="0"' >> eaccelerator.ini
echo 'eaccelerator.shm_only="0"' >> eaccelerator.ini
echo 'eaccelerator.compress="1"' >> eaccelerator.ini
echo 'eaccelerator.compress_level="9"' >> eaccelerator.ini

 

/etc/init.d/apache2 restart

For some clarity here is the exact config placed in /etc/php5/conf.d/eaccelerator.ini by above echo commands

extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/var/cache/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"

People who are lazy to copy paste from this post and like to have eaccelerator installed updated to a number of hosts (e.g. do some scripting automation) use install_upgrade_eaccelerator_debian.sh tiny shell script.

install_update_eaccelerator_debian.sh script is very useful for people who regularly update Debian to latest security updates.
Due to the fact eaccelerator is compiled from source code, after every update of Apache or PHP packages it is necessery to rebuild also eaccelerator, otherwise after upgrading Apache eaccelerator will stop silenty working, so if you don't explicitly check in phpinfo(); periodically you might even not have noticed that, except if you don't notice a bit of degraded performance after the last Apache / PHP update. Actually the need to re-compile eaccelerator PHP module, after each Apache or PHP update is a bit annoying and is downsize, that package has no native deb. There is one work around to that I can think of – just set install_update_eaccelerator_debian.sh to execute via cron routinely.
 I personally don't do that but people, as I don't like full automation, but people who prefer to install once eaccelerator and further forgot about it should:

a. Copy install_update_eaccelerator_debian.sh script to lets say /usr/local/bin

b. set a cronjob similar to

10 5,10,15,20,25,27 * * * /usr/local/bin/install_update_eaccelerator_debian.sh >/dev/null 2>&1

During execution the cron would put some extra load on the system but at least, you can be sure you will regularly be running with working / updated (re-compiled) version of Eaccelerator.

To test if eaccelerator is loaded on the system check in phpinfo(); function output. Create anywhere in a site DocumentRoot a file like php_info.php with content:

<?
phpinfo();
?>

Access the site in browser and look for eaccelerator in it. If eaccelerator is configured to serve well you will see something like on below screenshot:

eaccelerator php cache engine debian squeeze screenshot

Install eacceleartor php load up info debian squeeze linux shot
One note to make here is Eaccelerator might be creating problems due to caching on some hosts using Smarty Framework for a site basis, I assume with some other PHP Frameworks there might be some problems too but in general due to my experience so far I've faced problems with sites due to eaccelerator in very rare occasions in maybe 50 Eaccelerator installs so far, there were issues due to caching only on maybe 2 or 3. However I should share Eaccelerator is not recommended on testing Apace + PHP server for web development, as on those it sometimes might be creating "dev. time lags" in development due to caching – a common example for that is when a developer substitutes a .php with another similar ones whose size is identical to the previous .php script ….

After installing the system load dropped a bit, there is plenty of benchmarking online comparing Eaccelerator with other popular PHP Cachers like XCache, APC, PurePHP etc. – According to benchmarking done between the 3 Eaccelerator is maybe the most fastest PHP Cacher  – the article is a bit outdated but worthy to read.
As a result of putting in use Eaccelerator now the system load is more gracefully distributed in time sar (system activity information) over time does not show moments in which the CPU was "stoned" idling at 0 – as before.

As a result of the resolved downtimes and Apache restarts, I see also in webalizer statistics increase in the amount of traffic (unique visitors). Only time will show for sure if this increased capacity of traffic serving is directly because of Eaccelerator or there were other factors too but as long as I didn't change nothing else on the host I think it is very likely it is thanks to Eaccelerator.
Another note to make here is that on PHP Zend Framework it might be Zend PHP Caching via APC is quicker than Eaccelerator.

P.S. : Sometimes you might need to clean Eacceleartor PHP Cache, as it might be cause for showing old cached pages; even though some PHP were updated – more n that here

I will be glad to hear from people who install Eaccelerator, some feedback, did you got decreased server loads and more stable and quicker served pages?

I would like to also to give thanks to this nice blog article which was along the articles which help me with install guideance and hence was a kind of inspiration of this a bit prolonged but hopefully informative article.

After all, increased "Apache thoroughput" and more served connection without changing (spending on new hardware) is way to increase ur business efficiency and save money 🙂

Njoy 😉

Share this on:

More helpful Articles

Download PDFDownload PDF

Tags: , , , , ,

One Response to “Install Eaccelerator PHP cacher to decrease server CPU load on Debian Squeeze GNU / Linux”

  1. local business internet marketing says:
    Safari 5.1.9 Safari 5.1.9 Mac OS X  10.6.8 Mac OS X 10.6.8
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.59.8 (KHTML, like Gecko) Version/5.1.9 Safari/534.59.8

    The process of search engine optimizing is currently overrun by Black Hat SEO and also White Hat
    SEO practitioners. “white hat” refers to any SEO technique that follows
    acceptable guidelines. Certain White Hat SEO techniques may increase these
    risks, but some others can drastically reduce the risk of being removed from search engine indices.

    View CommentView Comment

Leave a Reply to local business internet marketing

CommentLuv badge