Speed up socialengine using Memcached / APC /Xcache in 2017

Recently we were working on the migration of socialengine v2 to socialengine v4.1.4 for one of our clients. The current socialengine website was loading very slowly even though there were not much users on the site. We tried to speed up the site by using the APC opcode, compressing the html, js and css but couldn’t improve the performance much. There were various reasons for the slowdown but main reason was due to unorganized and inefficient customized source code developer by the earlier vendor. The customized code was tightly coupled with the socialengine’s core code that we couldn’t migrate it to socialengine v4.1.4 using the migration scripts. We had to rewrite the customize code from the scratch for the obvious reasons after migrating the socialengibe v2 to v4.1.4. We shall discuss about the social migration in different article and in this article would focus on speeding up the socialengine v4.x using the caching.

Caching is the vital part of any website and helps website to respond quickly. Social engine allows variety of caching solutions like file based, memcache, APC (Alternative Php cache) and Xcache for the platform. Using one of the caching solution would speed up performance of the socialengine 4. If you don’t have configured the memcached or APC or Xcache then you can use file system based caching but its much slower than the other caching solutions. We would recommend to use one of the caching solution to speed up the socialengine. In this article, we should show the instructions to install and configure caching for socialengine. We assume that the socialengine is running on the production mode.

Memcache is a distributed caching which can be used in a scenario where application is running on several web servers. All the data stored in memcached would be distributed across the all webservers. Since it requires dealing with network protocols in order to support the distributed part of caching, it is slower compared to APC/XCache cache in case of application is running on single server. While using APC/Xcache on distributed system would require manual copy of data on all the servers. APC/XCache are non distributed cache and data can be stored on the local web-server only. APC/XCache op-code caching saves on the compile and execution times of PHP thus loading of the socialengine become faster. Some people got confused whether Memcached can be used with the APC/Xcache (opcode). We can use the combination of MEMcached (as data storage) and APC/Xcache (as opcode for php).

Now we are going to show the installation and configuration of Memcached, APC and Xcache for socialengine on Centos.

Install and Configure Memcached with socialengine

1) Install memcached

  wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar zxpfv memcached*
cd memcached-1.4.5
./configure
make install
./memcached -u memcached -d -m 64 -l 127.0.0.1 -p 11211

2) Install PHP Extension.

Download and install latest stable memcache version from PECL.

wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
phpize
./configure
make
make install

memcache.so will be install in php modules directory, now enable memcache.so extension in php.ini

To find out your php.ini location, execute following command

php -i | grep php.ini
Configuration File (php.ini) Path = /usr/local/lib
Loaded Configuration File = /usr/local/lib/php.ini

vi /usr/local/lib/php.ini

extension = “memcache.so”

save the file and restart httpd server.

/etc init.d/httpd restart

To check is memcache extension loaded inphp, execute following command.

php -i | grep memcache
memcache
memcache support = enabled

3) Configure memcached in socialengine

1. Go to http://yourserver/index.php/admin/core/settings/performance
2. Enable caching with memcached and add parameters specific to memcached.
3. Save the changes

Install and Configure APC with socialengine
By default there can be one opcode caching for php so if there is already any opcode (eaccelerator etc.) then disable that to allow APC to act as opcode.

1) Install APC

yum install php-pear
yum install php-devel
yum install httpd-devel
yum install pcre-devel
pecl install apc
echo "extension=apc.so"  /etc/php.d/apc.ini
/etc/init.d/httpd restart

To check is APC extension loaded in php, execute following command.

php phpinfo()
apc.enabled=1

2) Configure APC in socialengine

1. Go to http://yourserver/index.php/admin/core/settings/performance
2. Enable caching with APC option.
3. Save the changes

Install and Configure Xcache with socialengine

1) Install Xcache

wget http://xcache.lighttpd.net/pub/Releases/1.3.1/xcache-1.3.1.tar.gz
tar -zxvf xcache-1.3.1.tar.gz
cd xcache-1.3.1
phpize
./configure --enable-xcache
make
make install

You would need to change timelib_structs.h to install Xcache
Find line:

#include

Replace / update as follows:

#include "timelib_config.h"

Create one password for Xcache administration:

# echo -n “yourpassword”| md5sum

Then open php.ini, and add the following append configuration directives.

[xcache-common]
zend_extension      = /usr/lib/php/modules/xcache.so

[xcache.admin]
xcache.admin.user   = "admin"
;how to create md5 pwd: echo -n "password"| md5sum
xcache.admin.pass   = "a364b1d54799c713b8a377de50f8ed3c"  #easywms.com

[xcache]
; Change xcache.size to tune the size of the opcode cache
; to disable: xcache.size=0
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
; someone said, if =64 will get problem

xcache.size         = 32M
xcache.shm_scheme   = "mmap"
; set to cpu count (cat /proc/cpuinfo |grep -c processor)

xcache.count        = 4
; just a hash hints, you can always store count(items) slots

xcache.slots        = 8K
; ttl of the cache item, 0=forever

xcache.ttl          = 0
; interval of gc scanning expired items, 0=no scan, other values is in seconds

xcache.gc_interval  = 0

; Change xcache.var_size to adjust the size of variable cache
; same as aboves but for variable cache, if you have not used xcache function in script,forget it

xcache.var_size     = 8M
xcache.var_count    = 1
xcache.var_slots    = 8K
xcache.var_ttl      = 0
xcache.var_maxttl   = 0
xcache.var_gc_interval =     300

xcache.test         = Off
xcache.readonly_protection = On
; for *nix, xcache.mmap_path is a file path, not directory.
; Use something like "/tmp/xcache" if you want to turn on ReadonlyProtection
; 2 group of php won’t share the same /tmp/xcache
; for win32, xcache.mmap_path=anonymous map name, not file path

xcache.mmap_path    = "/tmp/xcache"
; leave it blank(disabled) or "/tmp/phpcore/"
; make sure it’s writable by php (without checking open_basedir)

xcache.coredump_directory =   ""
; per request settings

xcache.cacher       = On
xcache.stat         = On
xcache.optimizer    = Off

[xcache.coverager]
; per request settings
; enable coverage data collecting for xcache.coveragedump_directory and
; xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)

xcache.coverager    = On
; ini only settings
; make sure it’s readable (care open_basedir) by coverage viewer script
; requires xcache.coverager=On

xcache.coveragedump_directory = ""

2) Configure Xcache in socialengine

1. Go to http://yourserver/index.php/admin/core/settings/performance
2. Enable caching with Xcache option and add user’s credentials.
3. Save the changes

Conclusion
We found Xcache little faster than the Memcached/APC for socialengine 4 and used it for our client’s website.

Please feel free to comments or suggest other technique of caching.

It is possible to do performance tuning by yourself, or getting developers to do this. However, in our experience, the community owners are really more focused on making their community an engaging experience via functionality or graphics. Similarly, most developers can write PHP code, but very few have the experience of various tools for improving performance. One of the solutions we thought was to bake this optimization right into the hosting, so we have teamed up with Acenet hosting to provide you hosting for SocialEngine and Phpfox with built-in PHP, web server and database performance enhancements. Custom optimization may be required when your community grows huge, but that is different for everyone and we will continue to provide it as a separate service.

Our Work

Please check out our socialengine performance tuning at:

 

References

Leave a Comment

Scroll to Top