Python Google App Engine中的预热服务是怎么工作的?

3 投票
1 回答
3170 浏览
提问于 2025-04-17 06:53

有人能给我举个例子,说明在Google App Engine的Python运行环境中,热身入站服务是怎么工作的么?

我看过这个链接:http://code.google.com/appengine/docs/python/config/appconfig.html#Inbound_Services,但是在发送GET请求后,它没有给我很多例子(我似乎总是无法捕捉到它)。

我的app.yaml文件是这样的:

application: whatevs
version: 1
runtime: python
api_version: 1

builtins:
- datastore_admin: on

inbound_services:
- warmup

handlers:
- url: /static
  static_dir: static

- url: /_ah/warmup
  script: main.py
  login: admin 

- url: /.*
  script: main.py

我的main.py文件是这样的:

def main():
    application = webapp.WSGIApplication(
                     [("/", views.LandingPage),
                      ("/_ah/warmup", views.WarmupHandler)
                      ],
                     debug=True)
    run_wsgi_app(application)

WarmupHandler看起来是这样的:

class WarmupHandler(webapp.RequestHandler):
    """
    Called on app init
    """
    def get(self):
        current_user = users.get_current_user()
        return

但是,WarmupHandler似乎从来没有被调用过(我设置了断点,还有很多调试代码)。我到底哪里做错了?

1 个回答

1

App Engine 只有在你的应用有持续的流量时才会发送预热请求。如果实例大部分时间都闲着,它就不会总是被调用。

撰写回答