Configuring Warmup Requests to Improve Performance Stay organized with collections Save and categorize content based on your preferences.
You can use warmup requests to reduce request and response latency during thetime when your app's code is being loaded to a newly created instance.
App Engine frequently needs to load your app's code into a freshinstance. Loading an instance can happen in the following situations:
- When you redeploy a version of your app.
- When new instances are created due to the load from requestsexceeding the capacity of the current set of running instances.
- When maintenance and repairs of the underlying infrastructure or physicalhardware occur.
Loading your app's code to a new instance can result inloadingrequests.Loading requests can result in increased request latency for your users, but youcan avoid this latency usingwarmup requests. Warmup requests load yourapp's code into a new instance before any live requests reach that instance.
If warmup requests are enabled for your application, App Engine attemptsto detect when your application needs a new instance and initiates a warmuprequest to initialize a new instance. However, these detection attempts do notwork in every case. As a result, you might encounter loading requests, even ifwarmup requests are enabled in your app. For example, if your app is serving notraffic, the first request to the app will always be a loading request, not awarmup request.
Warmup requests use instance hours like any other request to yourApp Engine application. In most cases where warmup requests are enabled,you won't notice an increase in instance hours because your application issimply initializing in a warmup request instead of a loading request. Yourinstance hour usage can increase if you decide to do more work, such aspre-caching during a warmup request. If you setmin_idle_instancesto greater than0, you might encounter warmup requests when those instancesfirst start, but they will remain available after that time.
Enabling warmup requests
Warmup requests are used by the App Engine scheduler, which controls theauto scaling of instances based on user-supplied configuration. With warmuprequests enabled, App Engine issuesGET requests to/_ah/warmup. Youcan implement handlers for this request to perform application-specific tasks,such as pre-caching application data.
The scheduler starts up instances when it determines that more instances areneeded. Warmup requests may appear inlogseven if they are disabled because the scheduler uses them to start instances.
Note that warmup requests are not guaranteed to be called. In some situationsloading requests are sent instead: for example, if the instance is the first onebeing started up, or if there is a steep ramp-up in traffic. However, therewill be a "best effort" attempt to send requests to already warmed-up instancesif warmup requests are enabled.
To enable warmup requests, add thewarmup element under theinbound_servicesdirective in yourapp.yaml file, for example:
inbound_services:-warmupRegistering your handler
You can register the script that handles warmup requests in your project'sapp.yaml file. For example:
inbound_services:-warmuphandlers:-url:/_ah/warmupscript:main.pylogin:adminThis example registers a handler to listen to warmup requests to the/_ah/warmup request path with themain.py file.
Creating your handler
Create a handler that will process the requests that are sent to/_ah/warmup.Your handler should perform any warmup logic that is needed by your app.The following example builds on the previous example:
importwebapp2classMyWarmUpCode(webapp2.RequestHandler):""" This class handles the warmup request. You should add any code that you need to execute in the `get` method, such as populating caches, and ensure that you return a successful HTTP response. """defget(self):# Your warmup logic goes here.# Return a successful response to indicate the logic completed.self.response.headers['Content-Type']='text/plain'self.response.write('Warmup successful')# ...application=webapp2.WSGIApplication([('/_ah/warmup',MyWarmUpCode),# Other handlers# ...])What's next
You might want to store values in an in-memory datastore such asMemcache, giving your appfast, query-less access to data.
For example, if you build and store a list of the current trending articles foryour site, you can build that list in the warmup and store it in Memcache. Whena user request comes in, App Engine doesn't need to perform anydatastore queries and the application can serve the user's request faster.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.