Wednesday, November 27, 2013

Are you ready for Black Friday?

For most of us, we think of the day after Thanksgiving as the beginning of the holiday shopping season. For the administrators, maintainers and programmers of online stores, it may be the busiest and most stressful day of the year. Is your marketing team already emailing thousands of customers regarding upcoming promotions? Are you ready for them all to show up on your site at the same time? Read on to learn how to prepare your server for large spikes in traffic, as shown below. Note that most of this article and instructions apply to servers running in Bitnami Cloud Hosting.


Resize your machine!
If you expect a significant spike in traffic and your server is not yet prepared, we strongly recommend that you re-size your machine in advance. IMPORTANT: Resizing your server will stop it so that it is unavailable for a few minutes, so make sure you do this when you typically have the least amount of traffic. Also, if resizing the disk is not necessary, you should avoid doing so, as it slows down the resize process.

If the worst-case scenario occurs and your server suddenly becomes unresponsive, it will probably be due to the larger-than-normal number of visitors on your site. The slower the server response is, the more often your users hit the Refresh button in the web browser, which makes things even worse.
You can re-size your machine to a larger instance type, but there are few things you may want to consider doing first:

- Let your users know about your performance problems. Update your Twitter/Facebook account statuses to let you them know that you are working on fixing things, and try to update it often so they are aware of the process. This may help to reduce the number of people who are constantly refreshing the site.

- Turn on your application's maintenance mode if possible. Some applications allow you to switch to a special read-only maintenance mode which informs the end-user that the page is unavailable at the moment but it is going to be back online soon. This way users will not try to refresh your page constantly. It also prevents them from running into further issues or inconsistent states for example when clicking the order button and getting a timeout.

Once you are ready, sign into the BitnNami Cloud Hosting console and go to your server manage section. Click the Resize button:



The bigger the instance you use, the better. While the cost may be higher, it will significantly improve your server's performance and, because you are running in the cloud, you can simply resize back down to a smaller server after the rush is over.

Once your server is back online, turn off the maintenance mode and wait for few minutes. All your users will want to try to access it now, which may cause performance problems again for few minutes but then the server load should return to a more normal state. This is the time when, if you use caching, all of the cached pages are regenerated. Observe your machine but do not make rapid decisions. If everything is ok, then update your Twitter/Facebook accounts.

Are Evil bots affecting your site performance?

Performance problems may also be caused by misbehaving Internet bots or some other malicious scripts trying to index or scan your site, accessing as many sub-pages as possible at the same time. Follow the steps below to see if this may be happening to your site.

First, analyze the last 10000 entries in your Apache access log. The first command will show you when the analyzed period starts and the second one will list the most active IP addresses.

$ cd /opt/bitnami/apache2/logs/
$ tail -n 10000 access_log | head -n 1
$ tail -n 10000 access_log | awk '{print $1}'| sort| uniq -c| sort -nr| head -n 10


Based on the results, you can check the IP addresses with the highest number of requests using the “whois” command. You may reject all of the requests from the specific IP address by adding the Deny option in the Apache configuration file. In the example below, we will reject the 1.2.3.4 IP address in the WordPress config:


<Directory /opt/bitnami/apps/wordpress/htdocs>
deny from 1.2.3.4


Before restarting Apache, check if your changes are okay by executing the following command:

apachectl -t

Then restart the Apache web server:

sudo /opt/bitnami/ctlscript.sh restart apache

Improving the performance of your site
Improving the performance of your site is not an easy task. There is not a "one size fits all" solution to any problem and good configuration requires lots of research, testing and depends on many different factors: application technology, installed application plugins/extensions, type of the application etc.

There are few things that you may start with:
  • Cache your pages and limit the number of requests to your database.
  • Minify your Javascript and CSS and minimize the number requests to your web server.
  • Use Varnish.
  • Use CDN.

We describe all these aspects in our wiki.


No comments:

Post a Comment