SocialEngine 4: Performance and Speed Enhancement Tips

Andrew - SocialEngine

This article provides performance and speed enhancement tips for the SocialEngine platform.


Choosing the right hosting package is the most important decision you will need to make when building your SocialEngine community. Social networking websites generate a lot of activity on a server, and you want to make sure that you have sufficient resources available to handle that activity.

Shared HostingShared hosting packages are usually the most inexpensive of hosting packages, however they are not suitable for high traffic websites. Shared hosting packages work by hosting as many websites as possible on a single server, and these websites share all of the available resources. In some cases, a shared server may contain hundreds or even thousands of active websites on the same server, which can quickly affect your websites performance. At the same time, hosting providers place strict restrictions on shared hosting packages, which can often result in frequent errors. Shared hosting packages are best suited for light or static content, but for heavily dynamic applications like SocialEngine, you should choose either a virtual private server (VPS) or a dedicated server.

VPS or Dedicated ServerAs mentioned previously, VPS and Dedicated server packages are your best choice when considering hosting packages. However, there are a few caveats to them.First, most hosting providers provide either a managed or un-managed plan for their VPS and dedicated servers. With managed plans, hosting providers assume the responsibility of assisting you with making changes to your server’s configuration, and will assist you in cases of malfunctioning server software. However, this is done at an increased cost. Un-managed plans on the other hand, are completely hands off and you should only choose them if you have experience with managing servers.

Next, choose a plan that comes with at least 2 gigs of memory. If your hosting provider offers a VPS or Dedicated server plan with 4 gigs of memory, and your budget can support it, choose the that option. The reason for this is SocialEngine uses the MySQL InnoDB storage engine for many of its database tables. InnoDB uses memory to store its indexes, as well as a cache of frequently accessed data; which allows most of SocialEngine’s SQL queries to execute in milliseconds.

Tips to improve PHP’s performance

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:

<span class="pln">apc</span><span class="pun">.</span><span class="pln">shm_size </span><span class="pun">=</span> <span class="lit">128</span> <span class="typ">If</span><span class="pln"> you install APC </span><span class="lit">3.1</span><span class="pun">.</span><span class="lit">9</span><span class="pun">,</span> <span class="kwd">use</span><span class="pln"> the following instead</span><span class="pun">:</span><span class="pln"> apc</span><span class="pun">.</span><span class="pln">shm_size </span><span class="pun">=</span> <span class="lit">128M</span>

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:

<span class="pln">kernel</span><span class="pun">.</span><span class="pln">shmmax </span><span class="pun">=</span> <span class="lit">134217728</span>

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 (…hp#ini.apc.stat), 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.

Looking for quality SocialEngine Hosting? Look no further than Arvixe Web Hosting

Tags: , , , , , , | Posted under SocialEngine | RSS 2.0

Author Spotlight

Andrew Cross

Hi, I'm Andrew. A am a 26, ICT Administrator which offers support to company's around the South Wales Area. I have created a few social sites for myself and other company's. So far 2 out of 3 have been successful using the powerful SocialEngine Script. I continue to try and help the community of SocialEngine by giving Support and Technical Help where possible.

One Comment on SocialEngine 4: Performance and Speed Enhancement Tips

Leave a Reply

Your email address will not be published. Required fields are marked *