【问题标题】:App Engine instance not starting with basic scaling but works with auto scalingApp Engine 实例不是从基本缩放开始,而是使用自动缩放
【发布时间】:2016-10-26 14:20:06
【问题描述】:

我正在尝试在 App Engine 上启动一个具有基本缩放功能的项目,但它无法启动。该应用程序适用于自动缩放。 /_ah/start 在应用程序处于自动缩放时返回 200。我不明白为什么应用程序只有在设置为自动缩放时才会启动。

这是app.yaml,这是一个非常标准的应用:

application: myapp
module: default
version: 1-1
runtime: python27
api_version: 1
threadsafe: yes

libraries:
- name: lxml
  version: "2.3"

handlers:
- url: /static
  static_dir: static

- url: /favicon\.ico
  static_files: static/img/favicon.ico
  upload: static/img/favicon.ico

- url: /_ah/(mapreduce|queue|warmup).*
  script: wsgi.application
  secure: always
  login: admin

- url: /.*
  script: wsgi.application
  secure: always

这里是background.yaml,除了实例类和缩放参数之外,这与app.yaml 相同:

application: myapp
module: background
version: 1-1
runtime: python27
api_version: 1
threadsafe: yes
instance_class: B1
basic_scaling:
  max_instances: 1
  idle_timeout: 10m

libraries:
- name: lxml
  version: "2.3"

handlers:
- url: /static
  static_dir: static

- url: /favicon\.ico
  static_files: static/img/favicon.ico
  upload: static/img/favicon.ico

- url: /_ah/(mapreduce|queue|warmup).*
  script: wsgi.application
  secure: always
  login: admin

- url: /(mapreduce|tasks).*
  script: wsgi.application
  secure: always
  login: admin

- url: /.*
  script: wsgi.application
  secure: always

当应用程序处于自动缩放模式时,/_ah/start 返回 OK 和 HTTP 代码 200。当它处于基本缩放模式时,我在日志中看到的所有内容都是重复尝试以 400 到达 /_ah/start 失败HTTP 代码。由于这些运行完全相同的代码,我无法理解这里发生了什么。我可能遗漏了一些明显的东西......但我看不到它。想法?

-- 已更新--

这是我使用curl 在本地访问/_ah/start 端点时看到的确切输出:

curl -i -X GET http://localhost:8000/_ah/start
HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 3
Server: Development/2.0
Date: Fri, 24 Jun 2016 09:08:06 GMT

Ok.

...以及设置自动缩放时在服务器上:

curl -i -X GET https://myapp.appspot.com/_ah/start 
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Fri, 24 Jun 2016 09:11:41 GMT
Server: Google Frontend
Content-Length: 3
Alternate-Protocol: 443:quic
Alt-Svc: quic=":443"; ma=2592000; v="34,33,32,31,30,29,28,27,26,25"

Ok.

...在服务器上设置基本缩放时它只是挂起。

【问题讨论】:

    标签: django google-app-engine


    【解决方案1】:

    您的通配符处理程序正在接受对_ah/start 的调用。您应该在 background.yaml 中为_ah/start 添加一个处理程序:

    - url: /_ah/start
      script: background_starter.py
      login: admin
    

    然后,您可以简单地返回 200。在 background_starter.py 中:

    print 'Content-Type: text/plain'
    print 'This is a dummy handler to return http 200, so you can use wildcard url mapping in app.yaml.'
    

    【讨论】:

      【解决方案2】:

      似乎djangae 内置的处理程序没有做一些必要的事情来使它工作,我不确定是什么。类似于 GAEfan 的建议,我提供了一个处理程序,虽然他不允许应用程序在线程安全模式下运行,所以这是我正在使用的 background_starter.py 文件:

      import os
      import webapp2
      
      from google.appengine.ext.webapp import template
      
      
      class MainPage(webapp2.RequestHandler):
          def get(self):
              self.response.out.write('{"status":"OK"}')
      
      
      app = webapp2.WSGIApplication([
          ('/_ah/start', MainPage),
      ], debug=True)
      

      ...这是对.yaml 文件的更新,以将其视为独立应用程序:

      - url: /_ah/start
        script: background_starter.app
        secure: admin
      

      【讨论】:

      • 没有login: admin,任何邪恶的人都可以启动你的后端实例。
      猜你喜欢
      • 2019-01-25
      • 2019-09-25
      • 1970-01-01
      • 2013-07-23
      • 2015-09-01
      • 2022-12-13
      • 1970-01-01
      • 2017-04-16
      • 1970-01-01
      相关资源
      最近更新 更多