Speed up Zabbix UI with xcache

I recently posted a quick way to speed up your Zabbix UI by enabling compression in Apache httpd. Check out that post here. Today we’ll take it a step further by installing and configuring xcache. These 2 posts will help you improve your Zabbix front end performance.

Xcache is a PHP opcode cacher, which will pre-compile PHP scripts and then caching the compiled script in RAM. The results should be fast page generation time as well as reduced server load.

You can install from source or RPM packages, depending on your distro.

Install from source

I grabbed the XCache source package to manually compile from

 wget http://xcache.lighttpd.net/pub/Releases/2.0.0/xcache-2.0.0.tar.gz

Unzip the file and check out the INSTALL file in the xcache-2.0.0 directory

 tar -xvpf xcache-2.0.0.tar.gz

Compilation and installation is pretty straight forward

 $ phpize --clean && phpize
 $ ./configure --enable-xcache
 $ make
 $ su
 $ make install

Once XCache binaries have been compiled and installed, you need to configure your PHP to enable this new module.

# su
 # cat xcache-2.0.0/xcache.ini >> /etc/php.ini
 # vi /etc/php.ini

Make sure the path to the xcache.so module in php.ini is pointing at the right place or you will get errors once you restart Apache httpd.

My xcache.so was in /usr/lib64/php/modules/xcache.so so I modified this entry in /etc/php.ini

 zend_extension = /usr/lib64/php/modules/xcache.so

Once you have saved your changes to php.ini, restart Apache and verify xcache has loaded

php -i | grep xcache

If you don’t see an error, xcache is working.

Install from RPM on RHEL/CentOS 6.5

yum install php-xcache xcache-admin

To verify xcache was loaded properly run:

php -i | grep xcache

If you don’t see an error, xcache is working.

XCache admin configuration

XCache has a web based administration portal that shows useful metrics on XCache activities.

If you installed from source, you will have to copy the admin files from the xcache source directory into your web server document root, or similar location.

cp -R xcache-2.0.0/admin /var/www/html/

If you installed from packages, modify the [xcache.admin] attributes in /etc/php.d/xcache.ini

After copying the files, I added a Location directive to httpd.conf to limit access to the admin.

<Location /admin>
    Order deny,allow
    Deny from all
    Allow from 192.168
</Location>

XCache admin requires authentication by default.  Credentials should be modified in the php.ini file under [xcache.admin]

[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "mOo"
;xcache.admin.pass = md5($your_password)
xcache.admin.pass = "<md5 password>"

Generate md5sum of password

echo -n "secreatpassword" | md5sum

OR XCache admin has a page that will create an md5 hash of your password under

http://<ip address>/admin/mkpassword.php

Bring up this page, enter a desired password, and hit submit query.  Copy the resulting hash into the php.ini file.

Restart Apache httpd and test your access to the admin.

http://<ip address>/admin

Now you have a working XCache and admin.  You should see improved Zabbix UI page load times.  I didn’t see as large of an improvement implementing XCache as I did after I implemented mod_deflate, but the stats in the XCache admin do show significant caching and file size reduction.  I count this as a win.

Let me know your results.


Speed up Zabbix UI with Apache compression

Once you start monitoring a lot of hosts through Zabbix you may find that the frontend UI starts to slow while loading pages.  A quick way to combat that sluggishness is to enable compression in Apache.

Apache uses the mod_deflate module to compress output from the server before being sent to the browser.

The quick and dirty way to enable mod_deflate for Zabbix is to modify your Apache configuration file, httpd.conf, and uncomment

LoadModule deflate_module modules/mod_deflate.so

After enabling the deflate module, you will need to add the following to your httpd.conf file.  I added it in the same area as some other IfModule entries

#
# enable output from your server to be compressed before being sent to the client
#
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml
</IfModule>

This entry will only compress the listed file types, html, plain text, and xml.  Check out the Apache httpd page for more details.

https://httpd.apache.org/docs/2.2/mod/mod_deflate.html

Save your configuration file and then test them before restarting Apache

/usr/sbin/apachectl -t

Restart Apache and you are good.

You can verify that compression is working with the Live HTTP Headers add-on to firefox, among others.

You will see entries related to Content-Encoding in the server responses

Content-Encoding: gzip

I have seen significant decreases in page load time by enabling compression.

I wrote a post on speed optimization techniques using xcache here. These 2 posts will help you improve your Zabbix front end performance.

You should notice a big improvement in the speed of your Zabbix UI after implementing these quick optimizations.

Let me know if this helps you.