Skip to content

Why am I seeing high latency with CloudFront cache hits, DNS delays, and slow OpenSearch in me-central-1

0

I’m running CloudFront with a custom domain and an ALB in me-central-1. Even with cache hits, external tests show 300+ ms latency, including 200 ms from DNS and connection delays. When I send requests in quick succession, the response time drops to an ideal 100 ms, but after a 20-30 second gap, DNS lookup jumps back to 100-150 ms. My ALB fronts an ECS Fargate service with keep-alive set to 3600 seconds and an idle timeout of 90 seconds, pulling data from an OpenSearch cluster in the same region. When the cache expires, the next request takes up to 2 seconds; ALB access logs show target_processing_time as the main culprit. Additionally, is OpenSearch slower in me-central-1 (UAE) compared to ap-southeast-1 with identical setups? Uncached requests in ap-southeast-1 take about 700 ms. How can I reduce DNS lookup time and overall latency?

2 Answers
1

external tests show 300+ ms latency, including 200 ms from DNS

Is the DNS lookup to a custom domain or cloudfront.net domain?

If custom domain, are you hosting your DNS service on Route 53? For custom domain, is this a CNAME or Route 53 alias record to cloudfront.net? A R53 alias record is likely to be faster. DNS results are cached by recursive DNS servers and clients, which translates to shorter latencies for subsequent DNS queries.

Which DNS server are you using for lookup?

Below are 2 DNS lookups to a d1s7tw5t7fz258.cloudfront.net domain using Google (8.8.8.8) and Cloudflare (1.1.1.1) DNS servers. Note the 15 ms and 44 ms times.

% dig d1s7tw5t7fz258.cloudfront.net @8.8.8.8

; <<>> DiG 9.16.28 <<>> d1s7tw5t7fz258.cloudfront.net @8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11208
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;d1s7tw5t7fz258.cloudfront.net. IN      A

;; AUTHORITY SECTION:
cloudfront.net.         60      IN      SOA     ns-418.awsdns-52.com. hostmaster.cloudfront.net. 1377556270 16384 2048 1048576 60

;; Query time: 15 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Apr 06 13:17:32 Malay Peninsula Standard Time 2025
;; MSG SIZE  rcvd: 125


% dig d1s7tw5t7fz258.cloudfront.net @1.1.1.1

; <<>> DiG 9.16.28 <<>> d1s7tw5t7fz258.cloudfront.net @1.1.1.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59874
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;d1s7tw5t7fz258.cloudfront.net. IN      A

;; AUTHORITY SECTION:
cloudfront.net.         60      IN      SOA     ns-418.awsdns-52.com. hostmaster.cloudfront.net. 1377556270 16384 2048 1048576 60

;; Query time: 41 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Sun Apr 06 13:17:55 Malay Peninsula Standard Time 2025
AWS
EXPERT

answered a year ago

  • Hi @MikeLim DNS lookup is for custom domain which is hosted on aws route53, it was CNAME record before, I have updated it to be an alias record to cloudfront domain. Query time is better with requests in frequent succession with google DNS servers but after some time it jump back to 200+ms, not so good with cloudflare. I am testing from UAE Region

  • Hi @Jahanzaib, DNS query results are cached. For a first time user to your site, only the first web request will have 200+ ms latency. Subsequent web requests from that user to your website will have good response. Similarly, if your web site is popular, DNS query results are cached by upstream recursive server, be it Google, Cloudflare or others.

  • Hi @MikeLim, Yess they are cached but i believe it is for a very short amount of time depending on the browser? Along with DNS there is initial Connection and SSL which takes around 120-160ms. We have implemented DNS prefetch on front end but it's not solving the issue entirely. Our api is a suggestions api so with every character that a user enters in search bar, a new api request is sent to backend (route 53 -> cloudfront -> ALB -> ECS). cached response has a time of ~60ms but there is always something from DNS lookup, initial connection or SSL that adds time hence making total response time around ~180-350ms. unless i frequently send requests.

0

There are several factors contributing to the high latency you're experiencing with your CloudFront setup in the me-central-1 region. Let's break down the issues and potential solutions:

  1. DNS and Connection Delays: The high DNS lookup times (100-150 ms) and connection delays are likely due to the geographical distance between your users and the CloudFront edge locations. CloudFront uses a global network of edge locations to cache and serve content, but the effectiveness can vary based on user location and edge location proximity. To reduce DNS lookup time, you could consider using Amazon Route 53 as your DNS service, which integrates well with CloudFront and can help optimize DNS resolution.

  2. Cache Hit Latency: Even with cache hits, you're seeing 300+ ms latency. This could be due to the distance between the user and the nearest CloudFront edge location. To improve this, you might want to analyze your user base's geographical distribution and ensure you're using the most appropriate CloudFront price class that covers your users' locations.

  3. ALB and ECS Fargate: Your Application Load Balancer (ALB) and ECS Fargate setup seems reasonable with the keep-alive and idle timeout settings. However, the high target_processing_time when the cache expires indicates that your application or database (OpenSearch) might be the bottleneck.

  4. OpenSearch Performance: The perceived slower performance of OpenSearch in me-central-1 compared to ap-southeast-1 could be due to various factors such as cluster size, instance types, or data volume. It's worth investigating if there are any region-specific differences in the OpenSearch setup or if there are any network latency issues between your ECS tasks and the OpenSearch cluster.

  5. Reducing Overall Latency:

  • Use CloudFront Origin Shield to reduce the load on your origin and potentially improve cache hit ratios.
  • Optimize your caching strategy in CloudFront to reduce the frequency of requests to your origin.
  • Consider using Amazon ElastiCache in front of OpenSearch to cache frequent queries and reduce load on the OpenSearch cluster.
  • Analyze and optimize your application code and database queries to reduce processing time.
  • If possible, replicate your OpenSearch data across multiple regions and use latency-based routing to direct users to the nearest copy of your data.
  1. Monitoring and Analysis: Use AWS CloudWatch to monitor the performance of your ALB, ECS tasks, and OpenSearch cluster. This can help identify bottlenecks and areas for optimization. Additionally, use CloudFront's real-time logs and standard logs to analyze cache performance and identify patterns in user requests.

Remember that latency can be affected by many factors, including network conditions, server load, and application efficiency. A holistic approach considering all components of your architecture is often necessary to achieve significant latency reductions.
Sources
Caching and availability - Amazon CloudFront
Evolving the architecture with Amazon CloudFront - Hosting Static Websites on AWS
Troubleshoot latency on calls or requests to Amazon ECS tasks | AWS re:Post
Speeding up your Amazon S3-based website using Amazon CloudFront - Hosting Static Websites on AWS

answered a year ago

AWS
EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.