7

I have a Lambda function that is executed through API Gateway. If I request the endpoint directly: https://9ishqo5dj7.execute-api.us-east-1.amazonaws.com/api/

Then the execution time average is 200ms:

direct latency

However, if I add an "edge-optimized" endpoint, like this: https://testsite.learn-serverless.org/

Then the execution time is higher:

cloudfront latency

It seems CloudFront is adding some noticeable latency instead of reducing it.

At first I thought (as explained here https://stackoverflow.com/a/49845124/72350) it could be because the website that I used to run the tests run inside AWS and going out of the AWS network to go to CF could add some latency, however, I've tried the same thing from a computer in South America and I get the same results:

CURL to https://9ishqo5dj7.execute-api.us-east-1.amazonaws.com/api/:

Lookup Time: 0,029
Connect Time: 0,078
AppCon Time: 0,382
Redirect Time: 0,000
Pre-transfer Time: 0,382
Start-transfer Time: 0,578

Total Time: 0,578

CURL to https://testsite.learn-serverless.org/:

Lookup Time: 0,125
Connect Time: 0,175
AppCon Time: 0,476
Redirect Time: 0,000
Pre-transfer Time: 0,477
Start-transfer Time: 1,074

Total Time: 1,074

Other test from Chicago, IL (using webpagetest.org), lead to the same results. TTFB: 440ms vs 730ms.

Any ideas?

Lambda function code: basic function with Python+Chalice, https://github.com/diegojancic/serverless-performance/tree/master/functions/chalice/base

Page used to test latency: https://latency.apex.sh

Alternate Regional APIG endpoint: https://testsite2.learn-serverless.org

UPDATE 1: One thing to note is how Route53 is configured:

route53 configuration

It's set as a standard CNAME, if I set it as an CNAME-"ALIAS", it doesn't work for some reason. Not sure if this can have side-effects, but thought it could be worth mentioning.

Diego Jancic
  • 7,280
  • 7
  • 52
  • 80
  • These are interesting observations (and that's a cool test site that I haven't seen before). From the computer in SA, what's one of the IP addresses that the edge-optimized endpoint resolves to? – Michael - sqlbot Oct 26 '18 at 09:27
  • @Michael-sqlbot the custom domain resolves to 54.230.57.57 while the 9ishqo5dj7... resolves to 54.230.57.158. The Lambda is in us-east-1. One thing to note is how Route 53 is configured. Updated the question.. – Diego Jancic Oct 26 '18 at 13:11
  • @DiegoJancic did you check if the response header indicated a cache MISS or HIT from the cloudfront? Do you have cloudfront caching enabled for your API? From what i've seen from cloudfront before it only starts to be effective when you have many hits on your endpoint, maybe you could try load testing on both endpoints and check the results. – Rodrigo Reis Nov 08 '18 at 18:03
  • @RodrigoReis it's a MISS, but that's correct I believe. The reason is that I'm not using CF for caching (so it would be a MISS), but for reducing latency and improving SSL handshake time. See https://aws.amazon.com/cloudfront/dynamic-content/ – Diego Jancic Nov 08 '18 at 18:10
  • 1
    @DiegoJancic got it. makes sense, so in that case the optimization would be about the route from your client until your api server, using the regional endpoints provided by cloudfront. Did you figure out where the extra latency was coming from? Maybe do a traceroute? – Rodrigo Reis Nov 09 '18 at 02:56

0 Answers0