September 4, 2020

6 CDN Testing Best Practices

Performance Testing

CDNs improve global availability and reduce bandwidth, as well as reduce latency. This is because they shorten the time it takes a server to receive, process and respond to a static request. Therefore, CDN testing to see the impact on your website traffic is a best practice for high demand websites. The results can help you decide to keep or change your CDN provider, or if you even need one.

This blog post will cover everything you need to know about how to evaluate the impact of a CDN on your website performance through CDN testing.

Table of Contents:

What Are CDNs?

CDNs (Content Delivery Networks) are servers that deliver web content to users according to their geographical locations. We can imagine a CDN as a container for static resources that is geographically distributed, or, in other words, a world-wide cache. Caching resources is very useful for shortening latency for web content that has global reach.

Nowadays, the internet is geared towards offering web applications with plenty of multimedia content. As a result, a web page could have hundreds of resources. So suppose we have an application hosted in the United States and a user is visiting our page from the UK - each of those hundreds of requests have to make the long journey from the UK to the United States and then back to the UK. That isn’t very efficient.

But with a CDN, when a user in the UK makes a request for a resource from an application in the United States, the DNS resolution is resolved by taking into account the CDN infrastructure that has the least latency and load.

If this is the first time the request has been made, or the version of the resource has expired, the CDN will solicit this request from the application’s server and cache it for future requests. But if the same or a different user from the UK makes the request again, the CDN will already have a cached copy of the content. It will be returned directly to this user if it has not expired yet.

As a result, the latency of the request will be much lower, because the CDN doesn’t have to go to the application’s server to retrieve the resource. It’s impressive how fast a resource is returned when a request doesn’t have to travel to the application’s server (from the UK to the United States), and instead goes directly to a server close to the user.

Why Test CDNs?

It’s no surprise then that CDN testing is included in the best practices for high demand websites. Testing your application to see how the use of a CDN impacts your performance is crucial for ensuring your system is fast and has low latency. So how do you evaluate the impact of your CDN and make sure it meets your needs?

How to Do CDN Testing

The following points will help you accomplish this.

Benchmark the CDN Provider

The first thing you should do is guarantee that your resources can be delivered faster with a CDN service than with your website server. To do that, compare the load test of your resources from the origin URL with the load test of your resources from the CDN server you are interested in.

When designing your test, check your Google Analytics reports in order to include your website’s most commonly used files in the steps of your script. Test different file sizes and types, and bear in mind that third-party content and server-side processing should not influence your decision, as a CDN can’t help you with those.

Load testing the original URL

If your website currently uses a CDN, you will first need to disable it in order to load test your original URLs. Then, make sure that all static resources are triggered. In order to trigger the static resources in Apache JMeter™, enable the “retrieve all embedded resources” option, as shown in the figure below. Now you can create your test scenario and run it.

how to load test a cdn

Load testing the CDN

If you don’t have a CDN, then you need to set one up. The steps for configuring a CDN depend on the specific CDN provider, but in general it’s a quite simple task. To allow the CDN provider to serve your files, you need to delete the existing DNS record for your static resources and create a CNAME to the one provided by your CDN. Then, for each resource on your website, you will have to replace its URL with the URL of the same resource on the CDN. For instance, the URL will become This could take some time to take effect on your website. So if you need to check that the CDN is working properly, you can take a look at the headers of the response to the static resources and you will see which server is responding.

For example, the website has the CDN Cloudflare activated, so when running a JMeter load test, notice that among the response headers, the server which is responding is the CDN and not the original server.

load testing a cdn with jmeter

Once the CDN is setup, you need to load test your website again by using the same script that will trigger the secondary requests. Here as well, you need to enable the “retrieve all embedded resources” option.

Once you ran both tests, you can compare the results and decide which method is fastest for you.

Monitor the Number of Trips to the Origin Server

A good CDN architecture should not have so many trips to the origin server. Therefore, we need to check that this is working properly.

One easy way in JMeter to test if your specific resource is being cached, is by paying attention to the response headers of the request. In the figure below you can see that the header ‘CF-Cache-Status’ has the value ‘MISS’. In the previous image, the same header had a ‘HIT’ value.

  • A ‘HIT’ value means the resource is served from the CDN cache
  • A ‘MISS’ value means the resource is served from the origin server
  • An ‘EXPIRED’ value means the resource was in cache, but the cache expired so it is served from the origin server too

These values could vary from one CDN to another but whatever they are called, it’s important to have them under control, to monitor how effective your CDN cache is. For example, if you have too many expired resources, you might need to reduce the expiration header of these resources, as this could lead to many unnecessary roundtrips to your server, causing things to slow down.

cdn load testing with jmeter

Choose the CDN Service Most Suitable to Your Key Areas

CDN is not a technology that you can take for granted, the CDN solution for your website may not be the most appropriate for another website as the strength of coverage in global regions varies from one CDN to another.  So, if you want to pick the most suitable CDN for your website, this implies that you need to know where your users are. When choosing one, answer the following question: Is the CDN really improving the performance in your key areas where you lack from servers or not Delivering into Japan from Australia is not the same as having servers in Japan, so if your CDN provider doesn’t have servers in Japan, you should contemplate the idea of switching to another CDN that has servers in Japan or closer to it.

Test from Multiple Locations

When it comes to performance testing, the fact that CDNs cache static resources such as images and JavaScript in distributed servers across a certain region or worldwide, requires testing from different locations and making sure the traceroute of your CDN is correct and isn’t sabotaging the response time of your resources.

The solution for this problem is simple. Set up different machines with JMeter in your key areas. Or, if you have users all around the world, you can use BlazeMeter, which provides on-demand geographic distribution of load generation.

Load Test HTTP/2

Most CDNs (like Cloudflare) enable HTTPS and HTTP/2. This is advantageous for users who have security requirements. But this means you also need to load test your website for HTTPS and HTTP/2, so make sure you use a performance testing tool that supports these protocols. Luckily, JMeter is one of them. So, if your CDN provider has HTTP/2 enabled automatically, you can use the JMeter HTTP/2 plugin to simulate your traffic in a more realistic way. For more information about load testing HTTP/2 with JMeter, visit this blog.

Monitor and Optimize Your CDN Over Time

Keep testing your CDN continuously by monitoring files requested from the CDN and from your origin server, to make sure it is working properly. Make sure that your CDN setup is up to date and that everything is working as expected even after a big power outage or a service update. Add alarms to the most important KPIs so you can follow up and make sure your website is always up to speed.

Despite what has been said, also keep in mind that in addition to the immediate results of your load testing, CDNs can bring additional benefits that can’t be measured in seconds. If you are a small company, CDNs services could have more servers and more engineers dedicated and better prepared to handle huge spikes. CDNs can provide nearly 100% of availability of your site, even during power outages or network problems, since they have automatic mechanisms that sense server availability, and redirect if a server goes down. What’s more, you can monitor and analyze the CPU, disk and network usage of your servers as they are supposed to receive less requests when a CDN is activated.

For all these reasons, we recommend that you pay attention to these points but also evaluate the long term revenue of your CDN and consider to transfer to a different CDN when your needs are not met.

That’s it. Now, you now know all about load and CDN testing. Share your experiences with us in the comments section below.

You can learn more JMeter for free through BlazeMeter University.


Related Resources: