Search code examples
phpgoogle-app-engineamp-html

Google App Engine - First Request is slow


I have a question regarding Google App Engine. I know that the first request will take longer time than second because of how instances are scaled. But in my case the difference is very huge. I have no manual scaling, just a standard automatic scaling and i would want to have some recommendation of what i should do.

This is my case: I have an AMP project(https://amp.dev/) of an e-commerce website. So i do not have any static URL that i can setup a warmup-request that Google App Engine recommend. The url is like this: amp.store/product/{productname}, so the {productname} is dynamic, i have over 1000 products and cannot send request to those url just to keep my instance live at all time.

app.yaml:

runtime: php55
api_version: 1
service: amp-page

handlers:
- url: .*
  script: main.php

skip_files:....


When i try the PageSpeed Insights from Google i get this error on first try:

Lighthouse returned error: ERRORED_DOCUMENT_REQUEST. Lighthouse could not reliably load the requested page. Check that you are testing the correct URL and that the server is responding properly to all requests. (Status code: 500)

Now when i try again just right after i often get 84/100(mobile) 99/100(desktop).

This is a huge difference, this is why i am asking. Would it solve the problem with Manual Scaling or is there any other way to keep my instance or request faster like the second try?

Thanks!

enter image description here


Solution

  • One option would be to create a cron job via your cron.yaml file that would request a known page every X minutes to ensure you always have one instance running.

    Create a single handler in your application that executes a php script and returns some sort of output. Something that isn't database heavy. Could be as simple as an echo "ok";