Search code examples
google-app-enginedev-appserver

AppEngine's dev_appserver.py super slow to warm up


I updated AppEngine on my Mac (haven't done so in a while). dev_appserver used to start almost instantly (I have a very small website), but it now takes 30 seconds. After the first start, it is fast again if I turn it off then on. But if I switch to another project and back to the first one it is really slow.

I ran it with --log_level=debug but it doesn't print anything while it is hanging. Any idea what's going on? What was a joy to work with became a nightmare. Let me know if you need any additional info (I have a python webapp, mainly serving static files)


Solution

  • When dev_appserver is first run, a new instance is deployed, this takes a bit of time due to all the setup and configurations it requires. This time is known as cold-boot.

    Now, when you "switch to another project and back to the first one", this process is repeated, thus another cold-boot.

    Yet, 30 seconds seams a bit too much. If you have updated your application recently, you could check your imported librarys in case one of them is taken too long to load. You can also read this blog post on Best practices for App Engine startup time, which states:

    Most of the time, a standard application importing a few modules should have a negligible impact on performance. However, when third-party libraries get big enough, we start to see them do weird things with import semantics, which can mess up your boot time significantly.

    If you need to get better performance, you can try using warmup requests:

    Use warmup requests to avoid request and response latency during the time when your app's code is being loaded to a newly created instance.

    UPDATE: There seems to be an issue with dev_appserver which is affecting it's functionality on version 219.0.1. As mentioned on the Issue Tracker:117145272:

    It turns out a recent change in dev_appserver (released with Cloud SDK 219) makes the start time slow, but only when dev_appserver is used with pydevd in debug mode

    It's recommended to upgrade the SDK to version 220 and install grpcio with pip install grpcio

    Also, as another workaround could be to downgrade the SDK version to 228 using this command:

    gcloud components update --version 218.0.0
    

    Keep in mind that downgrading is not recommended since it could open the door for security vulnerabilities. Use it with caution.