Why is my website slow?


  • Applies to: Grid
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: SSH, vi knowledge
  • Applies to: All DV
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: SSH, vi knowledge

Overview

This article will help you determine what is causing your website to load slowly and how to fix it.

READ ME FIRST

Unless the slowness is being caused by a problem on the machine level of your server, or by a "bad neighbor" effect, (mt) Media Temple cannot directly assist you with making your website faster, although we're happy to point you in the right direction. Other problems may need to be resolved with your Internet Service Provider, web developer, or system administrator.

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.

READ ME FIRST

Unless the slowness is being caused by a problem at the physical host server level, general customer support cannot directly assist (although we're happy to point you in the right direction). Other problems may need to be resolved with your ISP (Internet Service Provider), web developer, or systems administrator.

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside (mt) Media Temple geeral scope of support. Please take a moment to review the Statement of Support.

CloudTech_ProductPage_217x57

CloudTech Can Help!

If you're having trouble with the steps in this article, additional assistance is available via CloudTech, our premium services division. Our expert engineers can tweak and tune your server for optimal performance. For more information on what CloudTech can do for you, please click here.

Symptoms

Your website loads slowly. Basic HTML pages take longer than 2-3 seconds to load, and complex pages take longer than 5-7 seconds to load.

Diagnosis

There can be many different causes of slow loading times for a web page. Please reference the following steps and linked articles to determine more precisely why your website is being slow. The possible causes are arranged in the best order for easy self-diagnosis and resolution. However, you can start anywhere in the list.

Network problems: Is it everyone or just my local area?

Sometimes a website loads slowly not because the server is slow but because your network connection to the server is slow or intermittent at one of the network "hops" between your location and the server. The problem may not even be with your local Internet Service Provider. There are usually 5-20 different Internet Service Providers between your local computer and the server.

  1. One of the best ways to test for network problems is to run a traceroute from your computer to the server. A traceroute will show all of the network hops between you and the server, and how long your connection took to go through each one. It will also show network timeouts (with ***). Run the following command from your computer's command prompt:
    • Mac
      traceroute example.com
    • Windows
      tracert example.com

    See Using the traceroute command for detailed instructions.

  2. Another quick and easy test for network problems is to use a proxy server to load your web page. A proxy server loads your website from a third-party location and should hopefully bypass local network problems. Example proxy servers:

    If the site loads normally through the proxy server, but slowly for you, you've identified a network problem. Note that proxy servers will load your site a bit more slowly than normal, because the site basically has to be processed twice. Also, they may not load certain page elements, such as Flash or Javascript.

  3. Finally, you can ask friends and contacts who live in a different city to try loading your website. If it's fast for them, but slow for you, you've most likely got a network problem. You are also welcome to call into (mt) Media Temple when the issue is occurring, so that (mt) Media Temple technicians can test from our support center.

    For international customers: If you are separated from our United States data centers by either the Atlantic or Pacific ocean, this is likely where network problems will crop up. If you're having a friend test the connection, you may want to make sure they're located in the United States or Canada.

  4. What to do if you've identified a network problem: If you haven't already, run a traceroute. If the timeout occurs right away, check your local network and router. If it occurs at your local Internet Service Provider or later down the line, you should contact your Internet Service Provider. Even if they aren't the direct cause of the problem, they may be able to re-route traffic to your website through a different network path.

    You also have the option to simply wait out the problem. Most Internet Service Providers will have their connection up and running again within a few hours.

TIP:

A good way to think about the network path between you and the server is to imagine it as a train route. There are many different stations and sections of track between, for example, Los Angeles and New York City. And if the line through Denver is down, it may not be the fault of either Los Angeles or New York, but the trains still don't get through. They'll have to be either re-routed or delayed until Denver is back on the line.

Page-specific problems

You should also test whether the slowness is limited to specific web pages, or is universal for all pages on the server. Many modern web pages contain dozens of complex elements which drag down the overall load time of the web page, and would do the same no matter how powerful or fast the host server.

  1. Your first speed test page should be plain HTML. You may already have a page like this on your server, such as a readme.html page. Otherwise, feel free to upload this basic HTML page for testing:

    Filename: speed.html

    <html>
    <head>
    <title>Speed Test</title>
    </head>
    
    <body>
    Did this page load in under 3 seconds?
    </body>
    
    </html>
    			

    If the HTML page takes over 3 seconds to load, you may have a network problem or a web server problem. For network testing, see the previous section. For web server problems, you should now contact (mt) Media Temple for further assistance.

    If the HTML page loads in less than 3 seconds, please continue with Step 2.

  2. If your web page executes database queries before it loads, proceed with the next step, and also make sure that you check the database problems section below, because MySQL queries won't show up as separate elements in the next test.
  3. What to do if you've narrowed the slowness to a specific page: To identify which elements are slowing down your web page, you should use some additional diagnostic tools to break down your page load into individual items. Firebug and Pingdom are both great tools for this, and they are covered thoroughly in our General slowness caused by excessive includes article.

Database problems

Does your page incorporate any database queries? Most Content Management Systems (CMS's) like WordPress, Drupal, and Joomla make extensive use of the database to generate all website pages. Your next speed test should be for possible database server slowness. There are two easy ways to test for database problems:

  1. Log into phpMyAdmin and navigate through a few menu options. This executes several simple database queries. Note that browsing a very large database or table will still take time even if the server is functioning normally.
  2. Load a simple PHP page that makes a single MySQL connection through your web browser. Here's a sample page - replace 00000 with your site number, and password with the appropriate information for your database server:

    Filename: dbtest.php

    <?php
    $link = mysql_connect('internal-db.s00000.gridserver.com', 'db00000', 'password');
    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    mysql_close($link);
    ?>
    <?php
    $link = mysql_connect('hostname', 'username', 'password');
    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    mysql_close($link);
    ?>
    
  3. If phpMyAdmin or this connection script load slowly, you may have a database server problem. See Getting started with your MySQL GridContainer if you have a container, or contact (mt) Media Temple for further assitance. See the server load section below.
  4. What to do if you've identified a problem with database requests made by your page: It's quite possible for a single query to take several seconds to complete, if it's written inefficiently. Add three or four of these poorly-written queries to your page, and it will load very slowly. If your speed test indicates that there are no overall database server problems, you will need to look into the individual queries that are being executed when your page loads. You may also want to perform some database and database server optimization.

    Optimization:

    Query Analysis:

  5. The following SSH command is a very helpful tool for watching individual queries live as they are executed by your database server:
    watch "mysqladmin -h internal-db.s00000.gridserver.com -u db00000 -ppassword processlist"

    Note that you will need to replace 00000 with your site number, and password with your database password. The password goes right after -p without any spaces.

  6. The following SSH command is a very helpful tool for watching individual queries live as they are executed by your database server:
    watch "mysqladmin -u admin '-p`cat /etc/psa/.psa.shadow`' processlist"
  7. You may also be able to avoid database-related problems by reducing the number of queries required to display your web page. Try caching HTML versions of your most popular pages. Also, investigate any plugins you are using which make complicated or inefficient database queries and consider updating or removing them.

Server load

If you have a DV server, and you have determined that your page is loading slowly due to a server problem, you should continue troubleshooting with these articles:

If, after reviewing these articles, you notice no system resource limit alerts, try rebooting your server, in case there is a stuck process somewhere. If that does not resolve the slowness, your slowness is most likely due to a machine issue. Please contact (mt) Media Temple for further assistance.

(mt) Media Temple machine and software problems

Occasionally your (mt) Media Temple resources may be under high load or experiencing other technical difficulties. You are welcome to contact (mt) Media Temple if you suspect that this is the source of your slow website loading times.

  • Check http://status.mediatemple.net/weblog/category/system-incidents/ for known incidents.
  • Due to the shared nature of the Grid, you may occasionally experience brief periods of resource unavailability. (mt) Media Temple employs both automated and manual monitoring of the servers to keep these interruptions to a minimum. If you occasionally experience 5-10 minutes of slow service, however, this is not cause for concern. Our load balancing should rectify the situation shortly.