Python CDN Speed Test Script — Speed Test Demon




Simple python script I use to speed test CDNs. It’s open sourced under MIT license. The repository is: https://github.com/speedtestdemon/speed-tests and the python script is “test.py”.

The script takes a single input “URL”. Example usage: python3 test.py [https://d20zaq59cm4c4j.cloudfront.net/wp-content/uploads/2021/05/cf.png](https://d20zaq59cm4c4j.cloudfront.net/wp-content/uploads/2021/05/cf.png).

The script outputs these things:

  1. Cold cache, hot cache, and warm cache tests (in that order).
  2. The response headers for cold cache and warm cache tests. This is important to see the header that reports “Hit”, “Miss”, or “RefreshHit”. It ensures that you’re running the cold cache and warm cache tests correctly.
  3. The hot cache times are averages of 10 curls.

Unique notes about the CDN Speed Test Script:

Here is an example output of the python script:

-------------------------------------------------------------  
Testing "Cold cache speed"  
-------------------------------------------------------------  
Got headers:  
HTTP/2 200  
content-type: image/png  
content-length: 719983  
date: Fri, 25 Jun 2021 15:01:17 GMT  
last-modified: Mon, 07 Jun 2021 00:16:21 GMT  
etag: "52ae2ff2354d4a68e680b77b4da58985"  
accept-ranges: bytes  
server: AmazonS3  
x-cache: Miss from cloudfront  
via: 1.1 9e8d1ff1eee770054f1561535ab320b2.cloudfront.net (CloudFront)  
x-amz-cf-pop: DFW55-C3  
x-amz-cf-id: lQPqV7PnAuwl_52kDXS2rsC20kSrloThTOG8cN1fK-MHUce0NNIDIA==time_namelookup: 0.12467000000000000304  
time_connect: 0.02141099999999998560  
time_appconnect: 0.06681200000000001027  
time_pretransfer: 0.00020100000000000673  
time_redirect: 0.00000000000000000000  
time_starttransfer: 1.02790999999999987935  
time to download: 1.06810300000000002463  
time_total: 2.30910700000000002063  
-------------------------------------------------------------  
Testing "Hot cache speed"  
-------------------------------------------------------------  
10 requests done. Average:  
time_namelookup: 0.00173870000000000036  
time_connect: 0.02068409999999999693  
time_appconnect: 0.06124410000000000270  
time_pretransfer: 0.00024639999999999802  
time_redirect: 0.00000000000000000000  
time_starttransfer: 0.03418949999999999767  
time to download: 0.21361620000000000608  
time_total: 0.33171899999999998609  
-------------------------------------------------------------  
Testing "Warm cache speed"  
-------------------------------------------------------------  
Sleeping for 0.5 hr to move cache from hot to warm  
Got headers:  
HTTP/2 200  
content-type: image/png  
content-length: 719983  
date: Fri, 25 Jun 2021 15:01:17 GMT  
last-modified: Mon, 07 Jun 2021 00:16:21 GMT  
etag: "52ae2ff2354d4a68e680b77b4da58985"  
accept-ranges: bytes  
server: AmazonS3  
x-cache: Hit from cloudfront  
via: 1.1 7c556a1545ad08a01c9e86ad41ac73a1.cloudfront.net (CloudFront)  
x-amz-cf-pop: DFW55-C3  
x-amz-cf-id: ACpfQ14wbO_vjjAisApBAJkRphZQ7IbD4Lawc77eo_K5UM_3-yWPZw==  
age: 1804time_namelookup: 0.05657399999999999929  
time_connect: 0.02411100000000000743  
time_appconnect: 0.07374400000000000399  
time_pretransfer: 0.00145299999999998208  
time_redirect: 0.00000000000000000000  
time_starttransfer: 0.02921799999999999398  
time to download: 0.22752000000000000002  
time_total: 0.41261999999999998678
Enter fullscreen mode

Exit fullscreen mode

Test Methodology: how I test CDNs. I use this python script to test CDNs.

Cheat Sheet on Curl Performance Metrics: how to benchmark server latency with curl: explains the curl metrics outputted by the python script.

Jetpack CDN vs Amazon Web Services CloudFront: Jetpack surprisingly faster!, where I analyze Jetpack CDN using the python script.

Cloudinary vs CloudFront: Cloudinary crushes Amazon Web Services!, where I analyze Cloudinary using the python script.



Abu Sayed is the Best Web, Game, XR and Blockchain Developer in Bangladesh. Don't forget to Checkout his Latest Projects.


Checkout more Articles on Sayed.CYou

#Python #CDN #Speed #Test #Script #Speed #Test #Demon