5 Speed Enhancement Tips for SocialEngine
SocialEngine, with a great speed, is always what we need to make our users happy. In this tutorial, I will show you 5 simple tips to make SocialEngine fast as possible.
1. Install an opcode cache
One of the most important things you can do to improve SocialEngine’s performance is to install an opcode cache on your server. An opcode cache stores the compiled state of PHP scripts in shared memory, and uses it when the script is requested. This removes one big chunk of the PHP interpreter’s job, which is to convert PHP code to opcode. By itself, this can improve the performance of SocialEngine by as much as 5 times. There are a few opcode cache extensions for PHP (Xcache, eAccelorator and APC), however we generally recommend choosing APC.
Some of the newer releases of APC have been buggy and we would not suggest using them. Of all the versions of APC available, we would suggest using APC 3.0.19, 3.1.3p1 or 3.1.9.
2. Cache to memory, not to files
Of all the caching features supported by SocialEngine, File-based caching is by far the slowest. All the other caching features within SocialEngine cache to memory, and memory access speeds are many orders of magnitude faster than file access speeds.
3. Tweak APC’s configuration for better results
If you use APC as your caching feature within SocialEngine, edit your php.ini file on your server and raise the apc.shm_size directive to 128MB:
This needs to be done to avoid high fragmentation, which reduces the performance of APC.
A bit of warning, on some unix/linux servers, you may need to manually raise the value of the kernel.shmmax resource in order to allow APC to allocate 128M of memory. To do this, locate the sysctl config file on your server, usually /etc/sysctl.conf, and make the following change:
This change needs to be made prior to raising the value of the apc.shm_size directive.
On production machines, consider disabling the apc.stat directive ( which removes stat checks on PHP files. Please be advised that when this directive is disabled, any changes made to PHP files, will require APC’s cache to be cleared manually, in order for the file to be recompiled and the opcode cache updated.
4. Keep an eye out for PHP errors. Check your logs.
Errors or exceptions from SocialEngine are automatically logged in SocialEngine’s error logs, located in the temporary/log directory — you can check errors from the Stats > Log Browser page in the admin panel. If SocialEngine is excessively writing to log files, the increase in file writes can quickly effect performance. Some of the more common causes for errors are:
The use of two PHP extensions with opcode caching capabilities on a server (ie. APC, Xcache, eAccelerator or Zend Optimizer). If you plan on using APC or Xcache, all other opcode caching extensions should be disabled.
MySQli losing connection to the MySQL database. Usually fixed by enabling the mysqli.reconnect directive.
MySQL max connection errors. Usually fixed by lowering the value of the interactive_timeout and wait_timeout MySQL variables to 30 seconds.
If you come across an error and require assistance isolating the cause, please submit a support ticket.
5. Use mod_php5, or mod_fastcgid with APC
One of the common problems we see when APC is used, is the use of mod_fcgid with PHP, which on multi-core systems is a bad idea. Consider the scenario where there are 2 quad-core processors on a server. With 8 available cores, and mod_fcgid being used as the Server API, APC allocates 8 buckets in memory to store data. If you have APC configured to use 128MB of shared memory, APC 1GB of memory (8*128MB=1024MB = 1GB) end up being allocated. The presence of 8 APC caches leads to an increased cache misses, which puts more strain on the CPU.
To avoid this problem, you can use either mod_fastcgid or mod_php5 with Apache. If you have SocialEngine running on a server with no other websites, mod_php5 will prove better performance. If you have multiple websites however, where each website is under a separate user account for security reasons, you can use mod_fastcgid. 128M of memory for apc.shm_size — see #3, APC will be using 1gig of memory . Additionally, PHP will randomly use one of the shared memory containers created by APC for caching, resulting in increased cache misses and putting strain on the CPU.
Edited by Les, 19 February 2019 - 03:03 PM.