next.js app taking 15-25 seconds to load from “cold” on google app engine

676 views
Skip to first unread message

Alex Fox

unread,
Apr 20, 2020, 8:25:37 AM4/20/20
to Google App Engine

I am deploying a next.js app to a Google App Engine (standard) but I am having trouble with cold start times.


I am building locally then deploying the .next folder to GAE. On the first boot it takes 15-25 seconds to boot up. Looking at the logs I can see a log for a very long GET 200 request but there's not really any information about what is going on. 


See image below:


Screenshot 2020-04-18 at 17.13.29.png



When I run yarn start locally it boots up in < 1, which as far as I understand is running the same production build? It is almost as though GAE is doing a build before it eventually deploys..


Any pointers would be immensely appreciated!


Alex

Blaine Garrett

unread,
Apr 20, 2020, 4:38:06 PM4/20/20
to Google App Engine
That seems a bit odd.  I have a next.js app on Standard and goes from cold start to content paint  in approx 5 seconds with data fetching on the server.


What instance type and size are you using?
Does your getInitialProps make any REST calls, access a database, etc? If so, are those cold starting as well?
If you are using scaling that leverages /_ah/start handler, is it accidentally doing REST Calls, etc etc?
Do you use a custom server that might be doing something odd?

Alex Fox

unread,
Apr 21, 2020, 9:33:12 AM4/21/20
to Google App Engine
So I managed to improved the load times by enabling "serverless" in the next.js settings. This is enabled by default when deploying to ziet. I also added the /_ah/start warmup which essentially just keeps the instance alive.

All getInitialProps are just returning some basic context and I'm using GAE standard with the default server size.

Still a bit baffled but it seems to be working ok now.

Katayoon (Cloud Platform Support)

unread,
Apr 21, 2020, 2:12:24 PM4/21/20
to Google App Engine
Hello,

I would like to add that whenever you send a start request an instance is brought into existence and is initialized. So it needs some time to load the required libraries and resources to handle the request.

You may consider using warmup requests to load application code into an instance ahead of time. As explained in this document, warmup requests reduce request and response latency during the time when your app's code is being loaded to a newly created instance. You can provision min_idle_instances afterward so that a number of instances be kept running and ready to serve traffic without lag.

Alex Fox

unread,
Apr 22, 2020, 8:12:16 AM4/22/20
to Google App Engine
Yes.

I have implemented the warm up requests which has improved the performance greatly. 

So I understand, when a new instance is created what commands are run? Does it have to do a npm install and copy over resources, or is there more?

Thanks!

Blaine Garrett

unread,
Apr 22, 2020, 10:57:46 AM4/22/20
to google-appengine
I am fairly certain that it does NOT install/build on warmup. In fact, I skip deploying my pages and src folder via .gcloudignore






--
You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/Hd0z0nnBxLA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/36492fc1-3a01-4db2-a199-77cda7e7e3ea%40googlegroups.com.

Katayoon (Cloud Platform Support)

unread,
Apr 23, 2020, 12:40:57 PM4/23/20
to Google App Engine
As explained in the Instance life cycle, the instance must first load any libraries and resources required to handle the request. However, we (support team) are not aware of the internal commands that being used to load the libraries and resources internally.
Reply all
Reply to author
Forward
0 new messages