This is the fifth and final blog of "Staying 2 Steps Ahead of the Performance of Your Magento Site," a series of five entries from Hostway partner Cynch, an expert on optimization and a leading migration and IT management agency.
As your Magento website evolves, you’ll recognize two trends that will start to haunt you if you ignore their decline: uptime and performance. Both of these things will suffer if you don’t have the infrastructure in place to accommodate an increase in traffic. My team has seen customers’ online stores taken down by a simple search engine crawling because it couldn’t handle a small increase in unplanned traffic. In other scenarios, we’ve seen customers never apply security patches to their servers because they don’t want to reboot anything, and cause their website to be offline.
The solution? Distribute your website visitors between two web servers to be ready for both unplanned traffic and planned maintenance. Most hosting providers (even cloud providers) offer load balancing appliances to make deployment easier and more economical. These devices sit in front of your web servers (logically), accept the initial communication from your website visitors, and use an algorithm to decide which server to send the traffic to. If one of the servers is dead or offline, the load balancer will send all traffic to the other. The algorithm used, as well as the frequency of server availability testing, is usually customizable; your hosting provider can help you adjust the settings.
Something commonly overlooked when adding another webserver and a load balancer to your deployment is code, content and media synchronization. Both webservers need real-time access to the same Magento source code, plugins and templates so that they behave exactly the same when a request comes in. This can be easily solved by making sure that updates are made concurrently to both machines, or by improving your SVN or GIT deployment methodology. Media files (product images) need to be stored in a central location like a file server so that both webservers can read and write to the same location at the same time. One of your other servers can be designated as having this role, or sometimes you can consume this as a service from your hosting company. The keyword to use in your research and discussions is Network Attached Storage, or NAS for short.
The last major hurdle to overcome is Magento confusion about your active website visitors. When a customer adds something to their shopping cart or is in the middle of the checkout process, Magento stores that information into something called a “session store.” By default, Magento stores that session data on the disk of the webserver. Well, if you are distributing traffic between two or more webservers, you need to make sure that all servers retrieve and store that data in the same location. If you don’t do this, then your users may lose the contents of their shopping carts and/or be logged out after they’ve already logged in. Magento can be easily configured to store session data in the database or memcache, so have your developers look at the inline documentation available in the app/conf/local.xml file for more information.
While there are some prerequisite components at the infrastructure level, some small modifications to your Magento configuration will allow it to support load balancing. If you need better uptime and the ability to handle bursts of traffic, you may have no choice but to add load balancing as the next important project on your whiteboard.
This concludes our five-part blog series about optimizing your Magento e-commerce website. We hope that you have enjoyed reading through these topics as much as we have enjoyed writing about them. In the end, Magento is no different that any other web platform: It requires specific configurations and maintenance in order to run at its full potential.
Thank you to Hostway for arranging this forum for sharing our experience with all of you. We always enjoy sharing our expertise with others, so if you would like to know more, please don’t hesitate to contact us at www.cynchinc.com/design/contact.html.