SocialEngine Blog

SocialEngine is the best way to create a unique community website. Let your friends, fans or customers geek out about anything you want.

What’s Behind The SE4 Demo

A few weeks ago, our version 4 demo server was unreachable for roughly 7 hours. After gaining access to the server again, I reviewed the log files and deduced the problem was simply a result of extremely high traffic volume. The demo had been using file-based caching up to that point, and APC wasn’t installed, so increased activity on the demo resulted in excessive file I/O and CPU usage skyrocketed. Some time ago, I wrote up a support article that gave tips on how to improve SocialEngine’s performance, and after applying these changes to the SE4 demo, there was a remarkable improvement. I kept a rough outline of all of the steps I took in setting up the server, and after requests from a few clients, I decided to make this information available.

First Thing’s First

The most important thing you can do to improve loading speed for a SocialEngine website is to make sure that you have sufficient CPU and memory resources available. Knowing this, and knowing that the database and application would be running on the same server, I chose a server with 4G of memory and a Quad core processor. There are two reasons why I chose a server with 4G of memory:

  1. Our chosen hosting provider locked us into a predefined a Processor and Memory
  2. Having reviewed the demo database using the mysqltuner script, I saw that we were only using 1G of memory
mysqltuner --user <username here> --pass <password here>
[--] Data in InnoDB tables: 1G (Tables: 150)

A server with 4G of memory and a single Quad-core processor proved to be precisely what was needed for our usage.

There’s an element of uncertainty when moving an existing website to a new server, and with this in mind, I decided not to go with a traditional dedicated server. Instead, I opted for a cloud server at Rackspace for the layer of flexibility they provide in making changes to server configuration. From their control panel, it’s possible to migrate to a new instance with only a few minutes of downtime. Another reason why I chose a cloud server at Rackspace is because they allowed me to choose my preferred operating system, Ubuntu, and control panel software like cPanel or Plesk. Personally, I tend to avoid installing control panel software in order to keep server software as simple as possible.

To sum up what we have thus far:

Operating System: Ubuntu 10.04 LTS
Hosting provider: Rackspace
Memory: 4G
Processor: Quad-Core AMD Opteron(tm) Processor 2374 HE

Installing and Configuring Server Sotfware

After spinning up the cloud server, the first thing I did was to update the package manager’s local index:

sudo apt-get update

Next, I made sure all of the core build packages that I’d be using were installed:

sudo apt-get install build-essential autotools-dev autoconf gcc g++ gcc-multilib g++-multilib re2c make

After this, I built my LAMP stack:

sudo apt-get install mysql-server mysql-client apache2 php5 apache2-threaded-dev php5-common php5-dev php-pear php5-curl php5-gd php5-imagick php5-json php5-mysql php5-cli libpcre3-dev

Then, I installed APC:

sudo pecl install http://pecl.php.net/get/APC-3.1.9.tgz

Before I could make use of APC, I needed to increase the kernel.shmmax setting so that I could allocate 128M of shared memory to APC. To do this, I edited the file /etc/sysctl.conf, appended the following line:

kernel.shmmax = 134217728

and ran the command:

sysctl -p

to load the changes made to the sysctl.conf file. With this change in place, I could finally enable APC, which was only installed previously and not enabled. To do this, I created the file /etc/php5/conf.d/apc.ini and added the following to the file:

extension=apc.so
apc.shm_size=128

My next step was to make sure that the mysqli.reconnect directive was enabled. To do this, I edited the file /etc/php5/conf.d/mysqli.ini and added:

mysqli.reconnect=On

I then edited the /etc/mysql/my.cnf, and under the [mysqld] section, I added:

interactive_timeout=60
wait_timeout=60

There are a few other changes that I made to the MySQL configuration that were unique to this installation. Earlier, in this article I touched on how I used the mysqltuner tool to determine how much memory was being used by InnoDB, but the tool also suggests changes that can be made to MySQL to achieve better performance. The most important setting to change is innodb_buffer_pool_size.

The size in bytes of the memory buffer InnoDB uses to cache data and indexes of its tables. The default value is 8MB. The larger you set this value, the less disk I/O is needed to access data in tables.

This setting should be slightly greater than the amount of memory currently being used by InnoDB, and in the case of our demo, I raised the value to 1200M:

innodb_buffer_pool_size=1200M

MySQL can be sensitive at times, and a bit of caution is needed when configuring InnoDB. Misconfiguring InnoDB can prevent the engine from loading, which can produce a host of errors. After making changes to your my.cnf file, and after restarting the MySQL daemon, it’s a good idea to review the /var/log/mysql/error.log file for any errors.

The last change I made, which is less of a performance optimization, was simply to enable mod_rewrite which wasn’t enabled by default. To do this I ran the command:

a2enmod rewrite

To apply all of these changes, the Apache and MySQL daemons need to be restarted. To do this, I ran the following commands:

restart mysql
/etc/init.d/apache2 restart

These changes alone produced a significant performance improvement, but there is still one more change that needs to be made. SocialEngine is still using file caching. To use APC with SocialEngine, I went into the Admin > Settings > Performance and Caching page and made sure APC was selected.

exit(0)

The information included in this article won’t work for all SE4 communities, however these changes worked well for us given our particular needs. Finally, a word of caution to those with root access. I would not suggest executing any of the commands included in this article without understanding what they do and their intended purposes. When in doubt, man <command> and when man fails, Google.

24 Comments

  1. jdouk69
    Posted August 20, 2012 at 9:50 pm | Permalink

    What are your thought running nginx?

    • ShaunHarding
      Posted August 21, 2012 at 9:56 am | Permalink

      That’s more a personal preference. The web server won’t do that much and should have very little, or no impact, on how long it takes for PHP to output the response body for a page. You might notice marginal improvements in distributing static files, which I’d assume Nginx would provide slightly better results. The majority of a page request however lives in PHP executing SE4’s code and the time it takes for that code to be processed will depend on code’s the complexity as well as system resources. If you use MaxCDN and/or SE4’s S3 integration you can reduce the number of requests for static files that hit the web server, and over all performance should be the same.

      • molecular
        Posted August 21, 2012 at 10:16 am | Permalink

        All the complaints regarding SE latest version have they been solved? I and the rest of the SE community would like to see a post regarding this urgent matter.

        Thanks

  2. Guest
    Posted August 20, 2012 at 10:47 pm | Permalink

    Thanks

  3. Posted August 20, 2012 at 10:55 pm | Permalink

    nice share , what will be your suggestions on Amazon AWS ?

    • ShaunHarding
      Posted August 20, 2012 at 11:18 pm | Permalink

      If I was only moving our demo to AWS, I would probably choose a large EC2 instances, which is more or less the equivalent of a quad-core processor. It has more memory than we need, but having 4 CPU cores was a necessity for the demo in order to handle the current loads.

      AWS is pretty interesting though because has more toys. One of these days when I have more free time I plan on spending geeking out SE4 on AWS — Autoscale, RDS and ElastiCache across multiple zones — and see what I come up with :).

  4. Nick S.
    Posted August 20, 2012 at 11:32 pm | Permalink

    Interesting. Will keep an eye on this.

  5. Posted August 21, 2012 at 1:46 am | Permalink

    I suggest that you increase “apc.num_files_hint” and “apc.user_entries_hint” too based on the number of files that SE has. we change it to 10000 for the clients. the default value (1024) is too low for SE.

  6. Bruno
    Posted August 21, 2012 at 8:41 am | Permalink

    Hi All,
    Once again the technology used has priority over humans, it is not the technology that is suppose to serve the humans but the humans who are now serving the technology: by using a remote cloud technology (after the soon coming of SE5) the humans data are stored on a third party, this is not good for members privacy protection, instead of using third party cloud technology why not use a second server for data storage only ? who makes a great product famous the software or the people ? Good day to all.

    • Posted August 21, 2012 at 1:44 pm | Permalink

      Bruno, if you’re hosting your website with any hosting provider, your data is being hosted by a third-party. It’s not a cloud or non-cloud issue.

  7. Steve
    Posted August 21, 2012 at 10:24 am | Permalink

    Gezzz, a live site will be used MUCH more than your online demo. How slow is socialengine if your demo couldn’t keep up with demand…

    • Posted August 21, 2012 at 10:36 am | Permalink

      That’s the $64M question I have as well.

    • ShaunHarding
      Posted August 21, 2012 at 11:15 am | Permalink

      Server resources aren’t infinite, and are old demo server had very little. We were using the server for much more than just show casing our demo. For any web application, if you increase it’s load without increasing the amount of resources available to it, sooner or later something bad is going to happen. The demo didn’t go down because of SE4 slow. It went down because resources were limited and it’s resource needs exceeded what was available to it.

    • Posted August 21, 2012 at 1:43 pm | Permalink

      Steve, all heavily-trafficked sites have stability issues now and then. It’s not just a function of the software running on top. Shaun wrote this as a resource to help you avoid issues.

    • Host on Cloud
      Posted August 21, 2012 at 6:48 pm | Permalink

      its about how much resource provided to you on your server, you can’t run SE4 on Share hosting. you should have 4G of memory and Quad core processor to run it Faster.

      by the way we have tested SE4 on 512MB Ram Quad core processor and its running smooth, all you have to avoid unnecessary Plugins.

  8. Mercedes
    Posted August 21, 2012 at 10:57 am | Permalink

    I used to have speed problem time ago, fortunately it was arranged changing of hosting server (third try, and tried three shared hosting before these) I highly recommend you http://www.icebluehost.com/ which has support included :-)

  9. Mona
    Posted August 21, 2012 at 4:38 pm | Permalink

    I have just tried to install APC but then having problems accessing my admin panel. there is this message ” access denied” please help.

    • Host on Cloud
      Posted August 24, 2012 at 5:23 am | Permalink

      Install and Configure APC with socialengine

      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, execute following command.

      php phpinfo()
      apc.enabled=1

      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

  10. Peter Greifer
    Posted August 22, 2012 at 5:26 am | Permalink

    … “hosting your website with any hosting provider, your data is
    being hosted by a third-party. It’s not a cloud or non-cloud issue.”

    the big difference is that YOU can decide WHERE the database is located, eg. in which country.
    european and especially german privacy protection law makes it almost impossible to run a commercial community webiste storing pivate data “somewhere i dont know”. an alternative would be a to set up a contract with amazon webservices on privacy protection, how to handle with private data according to european law …
    i think they don´t really care about!

    did you ever think of these legal apsects?

  11. ElectroBuddha
    Posted August 22, 2012 at 7:42 am | Permalink

    Great tips !!!
    Could you please give us some info about current traffic statistics on your demo server so we could have a better picture of how much load this type of server (quad core, 4GB mem) is able to handle?

  12. ElectroBuddha
    Posted August 22, 2012 at 7:57 am | Permalink

    Is APC used only for data caching or does it also performs opcode caching ?

  13. Posted August 24, 2012 at 9:16 am | Permalink

    What do you recommend if we want to install on AWS?

Post a Comment

Your email is kept private. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>