Skip to content

CloudFront sometimes send delayed request to origin server.

0

Hi. I am working on deploying nginx + php-fpm server to CloudFront. All the php files are served with response header Content-Control: no-store, no-cache, must-revalidate from origin server so that CloudFront does not cache responses for those php files.

My origin server works perfectly by itself. And mostly cloudfront response fast like origin server. But occasionally, when it is accessed via CloudFront, sometimes (about 25% ~ 50% of trials) cloudfront fires request to origin server after some delays. (about 10 to 20 seconds) I was watching all the traffic to my origin server with tcptrack and whenever cloudfront response is delayed connection from cloundfront to origin server was delayed as described. It is painful cause the symptom is not consistent. Sometimes its fast but sometimes its delayed.

I want to know what makes this delay. Please guide me where to dig up. Thanks.

1 Answer
0

The behavior you're experiencing with CloudFront occasionally sending delayed requests to your origin server could be related to a few factors in how CloudFront processes requests and interacts with origin servers.

  1. Origin Connection Timeout and Attempts: CloudFront has settings for origin connection timeout and connection attempts. By default, CloudFront waits up to 30 seconds (3 attempts of 10 seconds each) before either failing over to a secondary origin (if configured) or returning an error. This could explain the 10 to 20-second delays you're observing.

  2. Origin Response Timeout: There's also an origin response timeout setting, which defaults to 30 seconds. This determines how long CloudFront waits for a response from the origin.

  3. Persistent Connections: CloudFront tries to maintain persistent connections with origin servers to fetch objects quickly. However, if these connections are dropped or not properly maintained, it could lead to delays in establishing new connections.

  4. Regional Edge Caches: CloudFront uses regional edge caches in addition to Point of Presence (POP) locations. If your content isn't in the POP cache, CloudFront might check the regional edge cache before going to the origin, which could introduce some delay.

  5. DNS Resolution: Delays could occur if there are issues with DNS resolution between CloudFront and your origin server.

To investigate further:

  1. Check your CloudFront distribution settings, particularly the origin connection timeout, connection attempts, and origin response timeout. You might want to adjust these settings to see if it improves performance.

  2. Ensure your origin server can handle the incoming requests efficiently. Monitor your server's performance and resource utilization.

  3. Verify that your origin server is consistently sending the correct cache control headers for all responses.

  4. Consider using CloudFront's real-time logs or standard logs to get more detailed information about request processing times and origin response times.

  5. If possible, test with a different origin server or location to see if the issue persists, which could help isolate whether it's a problem with your specific origin or a more general CloudFront behavior.

Remember that while CloudFront is designed to improve content delivery speed, the complex nature of distributed systems can sometimes lead to occasional delays or inconsistencies in performance.
Sources
Request and response behavior for origin groups - Amazon CloudFront
How CloudFront delivers content - Amazon CloudFront
Request and response behavior for custom origins - Amazon CloudFront
VpcOriginConfig - Amazon CloudFront

answered 2 years ago

EXPERT

reviewed 2 years 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.