Social Engine ... full throttle!
So, you went and got yourself a SocialEngine site, huh? Built that little online community you've been dreaming of for years? Now you have more than 50 users and your VPS or Colo can't keep up? You, my friend, need to learn some SocialEngine optimization techniques.
Specifically, what we'll be talking about here can be applied to most sites (like the previous article on Joomla! optimizations), but because I made the changes on a server dedicated to hosting a SocialEngine installation, there's a bit of a bend here that is specific to SE.
PHP OpCode Caching
There are a few PHP OpCode Caching systems out there, and each of them is really good at speeding up your site, unless it's a SocialEngine site. SocialEngine sites do not do well with APC; just bear that in mind - my pages wouldn't even render after the APC extension was installed; however, for most other instances, I would suggest APC over XCache or eAccelerator. OpCode caching has become one of my new obsessions, and I've found that no matter which one you choose (XCache for lighttpd or APC/eAccelerator for Apache's httpd), you're going to get an immediate, noticeable, very nice boost. The reason I break them out between the two major httpd flavors, is because once you've installed them, it becomes very apparent which flavor they were built under. APC still runs under lighty, but runs better under Apache. Vice versa for XCache.
For SocialEngine, on both flavors, I suggest eAccelerator. My client's issues surrounded a SocialEngine install on a 6 core processor / 8GB RAM server, killing the server off after 90 people signed onto the site. No, that's not a typo, ninety people. Basically, SE's lazy loading and MySQL queries are to blame; they're pretty poorly written and I won't be discussing how to optimize them here, but once you have a site with 5000+ subscribed users and 100 connected users, SE's out of the box setup becomes a real issue. Especially in searches (db queries) and on pages that have multiple mods loaded (lazy loading) (and let's face it, your homepage and each user's page is pretty useless without showing a bunch of different mods' information!) eAccelerator took peak server loads from 3000 (again, not a typo, the loads were literally 3000/3500/2700 at one point) down to 3.5/2.5/1.7 just a few minutes ago.
So here's the deal, there are a dozen places where you can learn how to install eAccelerator, but since I like the SEO benefits, I'll be place number 13. You have to call your hosting company, ask for Bob and...just kidding. If you have shell access (and I'm assuming you do because you saw VPS and Colo and kept reading), shell in, su to root and do the following:
wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
tar xjf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6
phpize
./configure
make && make install
Since you're already in the shell, follow that up with a quick php --ini to locate your php.ini file (now, just a side rant, why the hell have people been telling me to use locate or find for years, when PHP has a fricken built-in function to find the ini it's using? ARRG!) Once you've located your ini, open it in your favorite editor (nano rocks!) and add the following information:
extension="eaccelerator.so"
eaccelerator.shm_size="16" #or something appropriate - note size is in MB
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
For those of you who actually read the instructions on the eAccelerator site (good for you, you bell curve wreckin' geeks!), you'll know that I'm telling you to install this as a PHP extension and not as an extension to Zend. Why? It's faster, only about 10%, but then again installing something as an extension of an extension will have that minor side effect. Once you're done with that, close & exit your editor. Back at the prompt:
mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator
Note: you're probably fine with 0644, but I've found that sometimes SELinux installs have issues with letting people into the /tmp folder even if they *should* have access.
Now, restart Apache or lighty and check your PHP install (php -v) to make sure eAccelerator has loaded correctly. If you're nosy, like me, and want to see stuff in action you can copy the control.php file from the eAccelerator source directory into a directory under your web root to view what scripts are being hit and how often. You'll need to add the 'eaccelerator.allowed_admin_path = "/full/path/to/webroot"' to your php.ini and restart, but it's worth it, if you're nosy!

MySQL Performance Tuning
Yes, you can tune your MySQL server to deal with even the worst queries gracefully. SocialEngine's queries, I'm sorry to say, need some serious inspection by the developers. The search profiles and text option, when I searched for the word "torre" on the customer's site, looked like this. You can download it. This blog post is already getting long.
MySQL performance tuning comes down to running two scripts and using their output to tweak your my.cnf. I'm going to give you the same disclaimer they would: If you don't know better, don't fricken do it. I did a lot of research and borked my server numerous times. I also borked a customer's server. (Or two...) Thank goodness you made that backup, right? Oops, you didn't make a backup? Good thing I did.
Ok, since this blog post is getting super long and the scripts do a pretty good job of explaining themselves, I'm going to point you to the download pages, and bid you adieu!
Ok, one post script... If you don't want to do this, or would just rather have someone else do it, we'd be happy to get this done for you. Realistically, it's about two hours' worth of work (mainly getting the MySQL tweaks implemented). Drop us a line and let us know you need PHP/MySQL or SocialEngine optimization.
