Posts Tagged ‘Decrease’

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

Monday, December 3rd, 2012

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
 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/
-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
 make install
 mkdir -p /var/cache/eaccelerator
 chmod 0777 /var/cache/eaccelerator
 cd /etc/php5/conf.d/

echo 'extension=""' >>  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


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 tiny shell script. 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 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 script to lets say /usr/local/bin

b. set a cronjob similar to

10 5,10,15,20,25,27 * * * /usr/local/bin/ >/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:


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 😉

Decrease Debian Linux boot time through decreasing GRUB kernel boot timeout

Friday, October 5th, 2012

Default timeout set for booting GRUB in Debian Linux is 5 seconds. This is really long for (mobile) Desktop Linux users like me who frequently start and stop computer while moving from location to location. Thus I found it useful to decrease the boot timeout set in GRUB in order to decrease my overall boot waiting time.

hipo@noah:~/Desktop$ grep -i timeout /boot/grub/grub.cfg
set timeout=5

To decrease GRUB boot timeout I had to change timeout=5 to timeout=1.
That’s all enjoy 🙂

Optimizing Linux TCP/IP Networking to increase Linux Servers Performance

Tuesday, April 8th, 2008


Some time ago I thought of ways to optimize my Linux Servers network performance.

Even though there are plenty of nice articles on the topic on how to better optimize Linux server performance by tunning up the kernel sysctl (variables).

Many of the articles I found was not structed in enough understandable way so I decided togoogle around and  found few interesting websites which gives a good overview on how one can speed up a bit and decrease overall server loads by simply tuning few basic kernel sysctl variables.

Below article is a product of my research on the topic on how to increase my GNU / Linux servers performance which are mostly running LAMP (Linux / Apache / MySQL / PHP) together with Qmail mail servers.

The article is focusing on Networking as networking is usual bottleneck for performance.
Below are the variables I found useful for optimizing the Linux kernel Network stack.

Implementing the variables might reduce your server load or if not decrease server load times and CPU utilization, they would at lease increase thoroughput so more users will be able to access your servers with (hopefully) less interruptions.
That of course would save you some Hardware costs and raise up your Servers efficiency.

Here are the variables themselves and some good example:

# = 0 ( Turn off IP Forwarding )

net.ipv4.conf.default.rp_filter = 1

# ( Control Source route verification )
net.ipv4.conf.default.accept_redirects = 0

# ( Disable ICMP redirects )
net.ipv4.conf.all.accept_redirects = 0 ( same as above )
net.ipv4.conf.default.accept_source_route = 0

# ( Disable IP source routing )
net.ipv4.conf.all.accept_source_route = 0
( - || - )net.ipv4.tcp_fin_timeout = 40

# ( Decrease FIN timeout ) - Useful on busy/high load
serversnet.ipv4.tcp_keepalive_time = 4000 ( keepalive tcp timeout )
net.core.rmem_default = 786426 - Receive memory stack size ( a good idea to increase it if your server receives big files )
net.ipv4.tcp_rmem = "4096 87380 4194304"
net.core.wmem_default = 8388608 ( Reserved Memory per connection )
net.core.wmem_max = 8388608
net.core.optmem_max = 40960
( maximum amount of option memory buffers )

# like a homework investigate by yourself what the variables below stand for :)
net.ipv4.tcp_max_tw_buckets = 360000
net.ipv4.tcp_reordering = 5
net.core.hot_list_length = 256
net.core.netdev_max_backlog = 1024


# Below are newly added experimental
#net.core.rmem_max = 16777216
#net.core.wmem_max = 16777216
##kernel.msgmni = 1024
##kernel.sem = 250 256000 32 1024


Also a good sysctl.conf file which one might want to substitite or use as a skele for some productive server is ready for download here

Even if you can't reap out great CPU reduction benefits from integrating above values or similar ones, your overall LAMP performance to end customers should increase – at some occasions dramatically, at others little bit but still noticable.

If you're unsure on exact kernel variable values to use check yourself what should be the best values that fits you according to your server Hardware – usually this is done by experimenting and reading the kernel documentation as provided for each one of uplisted variables.

Above sysctl.conf is natively created to run on Debian and on other distributions like CentOS, Fedora Slackware some values might either require slight modifications.

Hope this helps and gives you some idea of how network optimization in Linux is usually done. Happy (hacking) tweakening !