Why is my website so slow?

My website is slow. I'm only using about a third of my CPU and I have 2GB of memory. Do I need to add more memory to make my site faster?

1 Reply

Website Performance

You can try upgrading the server to see if it improves performance, however I recommend you take a look at the full spectrum of potential issues to see if one or more of these are relevant to your situation, and see where you might find improvement.

There are a lot of different things that can affect a website's speed. We have to consider what is going on all along the way between the server and the browser.

When someone tries to access a web page, they usually enter a name of a site like example.com into the browser.

The browser doesn't automatically know anything about example.com, so it asks the computer to find out where to look for it on the network.

DNS Problems

The computer goes and sends a request to a DNS server (The internet's equivalent of a phone book). If DNS is not functioning or responding slowly, the page request will be delayed or never get sent out.

Network conditions between the server and the browser.

If the network between the server and the browser is experiencing issues, or if the participants are on opposite sides of the globe, this can lead to latency (the time required for the information to travel across the network) and packet loss (causing extra delay while one or both ends of the communication link repeat themselves endlessly trying to get across what they are saying–think of the last time you had a bad phone connection… Can you hear me now?)

If your DNS server doesn't know about example.com, it has to ask another server, and so on. At this point multiple messages have already traveled back and forth over the network just to get the address of where we are going to send our request. (imagine the extra time added by this.)

The browser then sends the request to the IP Address it gets for example.com, (IP addresses are the numbers that look like 203.0.113.55)

Static vs Dynamic

Simple static (unchanging) pages are much faster than dynamic ones in general. The fewer "moving parts", the less one part of your site will need to wait on another one and the less memory and processing that will need to be done to handle each request.

If our webpage is static, the Web Server loads it into memory from storage and usually caches it in memory so it doesn't have to read the file again, and shoots that page over the network to the browser's computer.

Additional Content Load by the Browser

The page may contain links to things that also need to get loaded like stylesheets, fonts, images, videos and javascript, so the web browser sends off requests for those things, which again it often has to wait for all these things to come back before it knows how to put it all together.

Dynamic Content

If the page needs to look things up, for example to find a customer records, or all the albums related to someones favorite band, then we have an additional source of slowness. The web server has to load and run a program that makes up a customized web page specific to that request.

Database Speed

Often this additional content is contained in a database (sometimes on a different server). In this case, the program writing the web page, writes or runs a program called a query and sends it to the database asking it to figure out how to get a bunch of related data. This request can take a long time to fulfill. Sometimes these requests have to run other queries themselves, i.e. What are all the countries whose name begins with 'U', now find all the cities in those countries.

Deadlocks

Sometimes a web site will spend time waiting for a page to load because another request is updating the information that the page needs.

Calculation Time

Often this additional content requires some math or processing to do. Long calculations add their own bit of latency to the puzzle.

Processor Speed

While the time spent performing calculations can be significantly effected by processor speed, in general this is almost a non-issue for webpages that spend most of their time reading and writing to the disk.

Encryption and Security

One math problem computers perform a lot these days is factoring prime numbers for encryption. Using SSL or TLS for secure web pages adds its own overhead to the web page's load time. At the cost of added security, we have to spend time encoding and decoding the content so it is safe from prying eyes over the Internet.

Memory Limitations

These programs can be small or large and may take up a lot of memory to run. In fact if they take up enough memory, it may limit the number of requests that the web server can handle at once.

Request Volume

If the server can only handle three requests at once, all other requests must wait before they can get the page they ask for.

Denial of Service Attacks

As more and more requests come in, it becomes more and more difficult for the web server to keep up. People sometimes deliberately overwhelm web servers by sending them more requests than they can handle, effectively shutting down the server or making it painfully slow to use.

Compromised Servers

People sometimes break into someone's server and use it for their own means. If your server is suddenly much slower for no apparent reason, your Linode may have been hacked. It can be very difficult to deal with a compromised server.

Conclusion

All of these factors and more effect the speed you perceive when your browse the web, so there is no one answer. Always consider the big picture and identify ways to reduce the impact of the largest contributors.

Additional Resources

Please see the following guides for additional information:

Configuring an Apache Web Server

Troubleshooting Apache Issues

Troubleshooting Memory and Networking Issues

Making Manual DNS Queries with dig

Using MTR to Diagnose Network Problems

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct