Published on May 29, 2014
Having a fast website today is critical, but what happens when you begin to suffer from your own success? Here's a few ways you can make MODX sites fly, resulting in better conversion and stickiness for your site visitors.
The Importance of Performance on the Web
A significant part of winning online is having a site that gets information to visitors fast. MODX has long been a leader in this due to site builders being able to control 100% of what comes out of it without hacking the core. But it doesn't matter if your site loads too slowly, or worse, crashes under load.
The following tips are the basics of what we have learned from years of helping people get the most out of MODX with our MODX commercial support services. While there's many more things you can do to optimize performance, these will usually make a noticeable improvement to any site where the following MODX best practices have not been employed.
Dealing with Image & Thumbnails
Dealing with image thumbnails happens for many sites, and for a lot of people that means phpThumb is involved. Unfortunately, while it's a very functionally-useful piece of code, it is not the most optimal when it comes to scaling even moderatly busy sites. In fact, phpThumb can crush even the largest of servers out there, especially when its evil sidekick, the Cache Manager Plug-in, is left on in production.
Tip #1: Avoid or disable phpThumb Cache Manager. While the Cache Manager Plug-in can be useful, it's also easy to fall into unintended misuse/abuse, leading to the destruction of any chance of your site performing well. Avoid it unless you really, really know what you're doing.
Tip #2: Use pThumb to generate thumbnails. Jason Grant did a great job creating this more performant alternative to generating thumbnails with scaling in mind. It is a drop in replacement for phpThumbOf so all you have to do is swap them out.
Use the latest PHP & Nginx
MODX loves updated software stacks. That's why at the time of this writing, MODX Cloud uses the latest stable branch of nginx 1.6.x and PHP 5.4.x with APC (see Tip #5). We're also in the process of validating SPDY and Pagespeed in MODX Cloud. These tools take advantage of modern browser capabilities and automatic optimization to help sites render more quickly, keeping site visitors happier and around longer.
Tip #3: The current versions of Nginx and PHP versions can improve site performance. Especially if you're coming from older versions; it can also pay to keep up with new releases, and explore optimization tools like Pagespeed and SPDY, too.
Learn Your ABCs: Always Be Caching
Caching is probably the most important thing you can do for any MODX project. It also gets into the geekier underpinnings of how the web works. Jason Coward wrote an excellent in depth article on caching. YJ Tso expanded on that one with more discussion and examples. Both should be required studies for any serious MODX site builder.
Caching also extends to the PHP server layer, via "opcode caching". In our experience, at the time of publishing this article we usually get better performance and reliability using APC compared to Xcache. But, that is likely to change over time. No matter where you are today, it's likely there will be something faster tomorrow, so it can pay to keep things up to date and evaluate options.
Tip #4: Always Be Caching (ABC). Always. Every time. Seriously. If you don't have the expertise to know if you're doing it right, get some help from someone that does.
Tip #5: Use an opcode cache. We've seen best results using APC, but any one is far better than none at all.
CDNs to the Rescue
There are more images, videos and audio files being served every day. There are also great services that do a much better job delivering these assets to end usrs called Content Delivery Networks. You should use them because they offload your server of a very specific task, and as a result make your sites perform much better.
To make it even easier, Garry Nutting will be releasing a MODX Extra that makes working with MODX users get 25% off for life, in addition to them kicking a little back to MODX for every signup there.
Tip #6: Use a Content Delivery Network. http://modx.com/maxcdn.
Throw Hardware at It
We've helped sites go from slow responseses and timeouts under load even with 96GB of RAM and 32 processor cores, to flying on 4 cores and 16GB RAM—with no outages. Similarly, we've helped build out infrastructure that uses load balancers, multiple webservers, multiple databases and Memcached or Varnish or Redis. Sometimes you just have enough traffic to justify more hardware, or the time involved in optimization is more expensive than extra boxes. When you can't squeak more out of your site using techniques like the ones above, you often need to give it more IO or processor.
Tip #7: Deploy more server resources. A quick technique would be to make more PHP workers available to your site to increase the number of maximum visitors it can sustain. Often this means getting a larger plan, bigger VPS or a dedicated box. And sometimes, it just takes multiple, highly-tuned servers.
There is a lot under the hood that savvy site builders can do to make MODX sites sing. There's also a lot more that can be done like creating function-specific Snippets to replace much-loved but sometimes suboptimally-performing "generic" Snippets for sites with heavy visitor load.
Making the most of MODX is a process, not a destination, that changes over time. If you ever want to reach out for help improving MODX site performance, and in the process help fund ongoing MODX Development, we're happy to talk.