Skip to main content

How to flush the Fastly cache

Comments

2 comments

  • Dan Morrison

    Can use the API to check the fastly service performance also.
    One important thing is the hit ratio. To see what it’s been like in the last 24 hours:

    I’m on OSX, where the date function is non-standard, so I’ll use php to generate a timestamp for yesterday to define a request range.

    For Grid, where the environment is master, do this. If your production environment is named differently, adjust accordingly.

    FASTLY_SERVICE_ID=$(platform --project=$PROJECTID --environment=master variable:get env:FASTLY_SERVICE_ID --pipe)
    FASTLY_API_TOKEN=$(platform --project=$PROJECTID --environment=master ssh "echo \$FASTLY_API_TOKEN")
    FASTLY_API_URL="https://api.fastly.com"
    yesterdayTS=$(php -r "echo(strtotime('yesterday'));")
    
    curl -s -H "Fastly-Key: $FASTLY_API_TOKEN" \
        "${FASTLY_API_URL}/stats/service/${FASTLY_SERVICE_ID}?by=day&from=${yesterdayTS}" \
        | jq ".data[].hit_ratio"
    

    example response:

    0.7552160529016075
    

    75% is not great.

    There are a hundred other sats in that response you can investigate also.

    Try

    curl -s -H "Fastly-Key: $FASTLY_API_TOKEN" \
        "${FASTLY_API_URL}/stats/service/${FASTLY_SERVICE_ID}?by=day&from=${yesterdayTS}" \
        | jq -r '.data[] | "hits:\(.hits)" , "miss:\(.miss)" , "pass:\(.pass)" , "----",  "requests:\(.requests)"  '
    

    for a slightly extended report.

    hits:6624
    miss:2147
    pass:25633
    ----
    requests:34446
    

    This shows that the fastly report of 75% “Cache hit ratio” may be misleading as a guide to app performance, as the vast majority of the requests here were given a PASS, and Fastly chooses to not count PASS in the hit/miss summary.
    In this case, the number of requests hitting the server vs the number of requests that Fastly intercepted is MUCH greater than it seems.

    So your app may be suffering badly even when Fastly says it’s being efficient!

    0
  • Dan Morrison

    At some point the convention for variable naming was changed.
    FASTLY_SERVICE_ID became FASTLY_API_SERVICE
    so check what is really set in your environment and adjust the examples accordingly.

    0

Please sign in to leave a comment.