Let's take a look at how CDNs work, how and why to load test them, and some best practices to keep in mind when doing so.
What’s a CDN?
A content delivery network is a network of servers that delivers content to users based on their geographic location. For example, a visitor from Spain that wants to view a web page in the United States may be served a cached version of the web page stored on a server in Portugal. The response and load times are much faster since there's less distance for the request to travel between client and server.
With the rise of MaxCDN and AWS CloudFront, CDNs have become accessible to businesses of any size to improve availability, bandwidth usage, and latency. They’re especially useful for high-demand websites that experience a lot of international traffic, where they can balance the load and ensure slow requests aren’t holding up the server. In addition to improving the user experience, this helps reduce resource costs for the original server.
The most common way to leverage a CDN is to send requests for assets (e.g. images, scripts, stylesheets, videos, etc.) to a CDN rather than your server. For instance, the asset path `https://www.mysite.com/script.js` might change to `https://cdn.mysite.com/script.js`. The CDN fetches the actual `script.js` from your server and pre-caches it, so there's no need to upload files to different servers and manage them.
Why Load Test CDNs?
Many test engineers ignore third-party resources when load testing their applications. For example, they may mock third-party API calls or use static assets paths. The reason is simple: A temporary availability issue with a third-party resource could cause a load test to fail when there's no problem with the underlying web application code. However, there are some compelling reasons to build load tests for your CDN providers.
CDNs must be configured properly to deliver the performance gains they promise. Suboptimal cache settings, too many edges nodes, or other configuration issues can lead to performance problems that are difficult to diagnose in production. For example, you may have too many expired resources that lead to requests redirecting to the original server rather than being served from a cache. Adjust expiration headers can fix these issues.
There are many different CDNs with different features and geographic footprints, including MaxCDN, AWS CloudFront, and CloudFlare. If you have a high-performance application, the small differences in load times between these CDNs can have a significant impact on your bottom line. You may find that the CDN solution for one application isn't appropriate for another application given different regional coverage issues.
How to Setup a Load Test
There are several different CDN load tests to consider:
- Benchmark the CDN provider against your own server by running load tests with and without an active CDN. When doing so, it's important to distribute the load across different regions of the world to ensure diverse CDN usage.
- Analyze the cache status of each CDN-hosted resource to ensure there are minimal trips to the original server. If there are too many missed or expired resources, you may need to adjust the cache settings to be more effective.
- Load test the CDN using realistic amounts of traffic to see how it handles real-life loads before they actually occur. You can also see how these loads impact resource usage on the server compared to loading the assets without a CDN.
LoadNinja's Record and Replay Functionality – Source: LoadNinja
LoadNinja's record and replay functionalities make it easy to create load tests without complex scripts. With a Jenkins plugin, you can also easily integrate these tests with a continuous integration server. Any bottlenecks that are flagged in the tests can be diagnosed by analyzing navigation timings and the actual DOM in virtual user sessions.
Best Practices to Keep in Mind
Load testing may seem fairly straightforward — especially when using a tool like LoadNinja — but there are some important things to keep in mind when load testing CDNs to ensure you get the most accurate results.
Keep these factors in mind:
- Start with a benchmark. Benchmarks are necessary in order to compare results between CDN providers. Without a benchmark, it's hard to know what's good and what's bad in terms of performance. Start with a benchmark of CDN versus no CDN and then move on to comparing different CDN providers, if necessary.
- Run tests in different geographic locations. That way, you can analyze the true benefit of the CDN rather than testing just a single node in one location. LoadNinja makes it easy to distribute loads across different geographic regions in just a few clicks within its record and replay tool.
- Watch your KPIs over time. It’s important to set alarms for KPIs and follow up any issues that arise or if something seems off. Service updates, power outages and other issues can cause intervention-caliber problems.
The Bottom Line
CDNs are a great way to improve performance with minimal time and effort. By caching assets on servers around the world, you can minimize load on the original server and dramatically cut down load-time latency. Load testing CDNs can help you quantify these benefits, identify any configuration errors, and ultimately, choose the best providers.