How to Optimize Your Website for High Traffic Spikes

Updated by
James Parsons
on Sep 28th, 2022
Written by ContentPowered.com
Posted in How-to

There are a few reasons why the traffic on your website might suddenly spike.  Your site might be geared towards horror, and receive a spike in traffic every Halloween.  Your site might be a shop with a good promotion, with an incredibly wave of traffic for Black Friday.  You might produce an infographic that goes viral in an unexpected way.  How can you ensure that your site won’t go down when that massive flow of traffic hits?

Investigate, Upgrade and Reinforce Your Web Host

Your web host is going to be one of the biggest factors in determining how you can support traffic spikes.  In general, the cheaper the web host, the less resilient you will be to traffic.  You need to make sure your host has enough bandwidth to support incoming traffic.  You need to make sure their server can handle serving your pages on the volume that will be requested.  You need to make sure your web host isn’t going to shut down on you.  Most of the time, server hardware will be sufficient, unless you’re hosted on a virtual server with five other websites, all of which are getting as much or more traffic.

You will need to make the decision whether to stay with your current web host, upgrade to a new package with your current host or migrate to a stronger host.

Minimize Scripts and Plugins

Over time, running a site means accumulating code.  You want to run some analytics, so you install tracking code.  You want to run a plugin, so you add the code to your site.  You finish with the analytics so you cancel your subscription, but don’t remove the code.  You stop actively using the plugin, but you don’t uninstall it in case you change your mind.  Over time, your site grows bloated with code that loads and fails to execute.

At the next available opportunity, and at regular intervals in the future, audit your site for stray code, broken scripts, outdated plugins and other assorted digital garbage that has accumulated in your site code.  Streamline and remove as much as possible so you’re not slowing users down every time they try to load a page.

Compress and Optimize Images

Compress-and-Optimize-Images

Images are generally some of the largest files your site serves up, which is why many modern sites outsource their hosting to a content delivery network.  In order to lighten the load on your servers or the CDN, compress and optimize your images for the web.  There are a number of ways you can do this, from automatic tools to photography tips.  Smaller images load faster, and when you’re running an online store, loading a dozen thumbnails faster is a huge relief for your server resources.

Disable Comments

Comments require calls to a database or loading a third party plugin, depending on what comments plugin you’re using.  This takes a significant amount of time.  Syncing the flood of comments that comes with a viral piece of content adds significant strain to your servers, or slows down your users as they wait for the taxed plugin.  Disabling comments, at least temporarily, allows you to eliminate that avenue of server strain.

Optimize Server Connection Handling

If you have access to the apache root for your server, you can make a few manual adjustments to your server itself to better handle a flood of traffic.

The first is to navigate to your /etc/httpd/conf/httpd.conf file and open it.  There will be a line labeled ServerLimit, and another labeled MaxClients.  These numbers are limits to the number of simultaneous connections your server will handle at a time.  Adjust both of these numbers upwards, keeping them the same.  This will allow a few extra users at a time to access your site.  Don’t make the numbers too high, or your server will physically lock up.

The second thing to do is find the KeepAliveTimeout line.  Your web server keeps a connection alive while waiting for input from a user; this number is how long that connection is kept alive.  The default is 15 seconds, which is a long time to tie up your server when your site is being flooded.  You can set this to a lower number, even as low as 1 second, without issue.

You will need to save the file and restart your server, leading to some minor downtime, so make these changes during off hours.

Cache mySQL Queries

Cache-mySQL-Queries

One common way a server seizes up during high traffic is when a mySQL database is overloaded.  You can navigate to your etc/my.cnf file and find the query_cache_size line.  Set it to something closer to 20.  This keeps the data from SQL queries cached for a longer time, so the server doesn’t need to ping the database as often.  Again, restart your server to apply the changes.

Minimize Database Queries

If you use WordPress, Joomla or another management system for your content, you may be calling on your server much more often than is necessary.  These systems tend to use PHP where static HTML can do just fine.  Rather than calling a database to populate URLs, you can set the static HTML link to that URL just as easily.  It’s no different for users, except it lightens the load on the servers.  You can find more information in the link for server adjustments above.

Create a Streamlined Site Version

One option you have, if you have time to plan, is to create a version of your site that is intentionally pared down.  Strip out comments, scripts, widgets, plugins and most of your non-essential images.  Create a low-fi version of your site that can be toggled on when your site begins to see a massive amount of traffic.  You can set a script to determine when your site is hammered with traffic and automatically serve the streamlined version, or you can toggle it manually when you notice the influx.

Use a Content Delivery Network

As mentioned above, using a CDN takes a lot of the strain of hosting a site out of your hands.  Scripts and images are both often hosted by a CDN.  For that matter, embedding videos from YouTube is the same principle; you’re outsourcing the server load.  Sign up with a CDN and outsource that load, to make sure your site stays alive.

Invest in DDoS Protection

Sometimes, your incoming traffic is not from a viral surge or holiday influx, but from a denial of service attack.  In these cases, it’s a good idea to invest in some protection to help minimize the amount of bot traffic that gets through.

Written by James Parsons

James Parsons

James is a content marketing and SEO professional who enjoys the challenge of driving sales through blogging while creating awesome and useful content.

Join the Discussion

  1. Henrico Ellis

    says:

    James your post is spot on with this post.

Leave a Reply

Share
Tweet
Pin