Memory cache
timeit.timeit("requests.get('http://127.0.0.1:8080/200/http://127.0.0.1:8000/media/product_images/egg.jpg?a={}'.format(random.randint(100, 400)))", "import requests; import random", number=100)
100 calls = 3.4494818639941514
No cache
timeit.timeit("requests.get('http://127.0.0.1:8080/200/http://127.0.0.1:8000/media/product_images/egg.jpg?a={}'.format(random.randint(100, 400)))", "import requests; import random", number=100)
100 calls = 4.642427519895136
Request time imageproxy
timeit.timeit("requests.get('http://127.0.0.1:8080/')", "import requests; import random", number=100)
100 calls = 0.19692258187569678
Request time image
timeit.timeit("requests.get('http://127.0.0.1:8000/media/product_images/egg.jpg?a={}'.format(random.randint(100, 400)))", "import requests; import random", number=100)
100 calls = 2.757888172985986
- Request time total = 0.197 + 2.758 = 2.955
- Memory cache without requests = 3.449 - 2.955 = 0.494 => per image: 0.00494
- No cache without requests = 4.642 - 2.955 = 1.687 => per image: 0.01687
Memory cache (first hit)
timeit.timeit("requests.get('http://qa1-cdn.zageno.com/images/200/product_images/egg.jpg?a={}'.format(random.randint(500, 40000)))", "import requests; import random", number=100)
100 calls = 38.761549428105354
Request time imageproxy (first hit)
timeit.timeit("requests.get('http://qa1-cdn.zageno.com/images/?a={}'.format(random.randint(500, 40000)))", "import requests; import random", number=100)
100 calls = 7.778287201886997
Request time image (CDN, first hit)
timeit.timeit("requests.get('http://qa1-cdn.zageno.com/product_images/egg.jpg?a={}'.format(random.randint(500, 40000)))", "import requests; import random", number=100)
100 calls = 32.912963322829455
Request time image (cloud storage, first hit)
timeit.timeit("requests.get('https://storage.googleapis.com/qa1-cdn.zageno.com/product_images/egg.jpg?a={}'.format(random.randint(500, 40000)))", "import requests; import random", number=100)
100 calls = 44.388846822082996
Request time image (CDN, second hit)
timeit.timeit("requests.get('http://qa1-cdn.zageno.com/product_images/egg.jpg')", "import requests; import random", number=100)
100 calls = 7.552786473883316
Request time imageproxy (CDN, second hit)
timeit.timeit("requests.get('http://qa1-cdn.zageno.com/images/200/product_images/egg.jpg')", "import requests; import random", number=100)
100 calls = 6.2556377809960395
As far as I can see from the timings the image transformation doesn't have a considerable impact compared to the networking times.
Therefore I would strongly recommend to keep the imageproxy behind the CDN instead of e.g. doing transformations locally and upload different versions of an image. Because in that case we would still have the networking times on CDN first hit and it would only add complexity to our codebase.