3

現在、私の Google App Engine 設計には、URL フェッチを介して常駐バックエンドと通信するフロント エンドがあります。新しい設計では、バックエンドの代わりにモジュールが使用されます。これは Google が人々に望んでいる方向なので、難しいことではありませんが、これを本番環境で実行するのに何日も悩まされました。「manual_scaling」はうまくいきません。dev_appserver.py (1.8.3) の「manual_scaling」は正常に機能しますが、本番環境では機能しません。問題をできるだけ単純化しました。問題を再現する必要がある 4 つのファイルを次に示します。

ソースコード

app.yaml

api_version: 1
application: myapp
version: 123456
runtime: python27
threadsafe: true
handlers:
- url: /send_hello/.*
  script: send_hello.app
- url: /hello/.*
  script: hello.app

こんにちは.yaml

api_version: 1
application: myapp
module: hello
version: 123456
runtime: python27
threadsafe: true
#comment out these next two lines and it works!!!
manual_scaling:
  instances: 1
handlers:
- url: /_ah/start
  script: hello.app
- url: /hello/.*
  script: hello.app

こんにちは。

import webapp2
import logging
from google.appengine.api import modules

class HelloHandler(webapp2.RequestHandler):
  def get(self):
      who = modules.get_current_module_name() 
      logging.info("Hello from the '%s' module" %  who)
      self.response.headers['Content-Type'] = 'text/plain'
      self.response.out.write("Hello from the '%s' module!\n" % who)

mappings = [
   (r'/_ah/start', HelloHandler),
   (r'/hello/.*', HelloHandler)
   ]

app = webapp2.WSGIApplication(mappings, debug=True)

send_hello.py

import logging
import webapp2
from google.appengine.api import urlfetch
from google.appengine.api import modules

class SendHelloHandler(webapp2.RequestHandler):
   def get(self):
       url = "http://%s/hello/world" % modules.get_hostname(module="hello")

       logging.info('backend url: %s' % url)
       response = urlfetch.fetch(url=url, method=urlfetch.GET)

       reply = 'backend response: %d %s' % (response.status_code, response.content))
       logging.info(reply)

       self.response.headers['Content-Type'] = 'text/plain'
       self.response.out.write(reply)


mappings = [
    (r'/send_hello/.*', SendHelloHandler)
    ]

app = webapp2.WSGIApplication(mappings, debug=True)

開発サーバーでのテストはうまく機能します

起動すると問題なく動作し、手動スケーリング インスタンスが起動するのを確認できます

$ dev_appserver.py app.yaml hello.yaml
WARNING  2013-08-17 00:19:37,131 api_server.py:317] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO     2013-08-17 00:19:37,134 api_server.py:138] Starting API server at: http://localhost:34319
INFO     2013-08-17 00:19:37,147 dispatcher.py:164] Starting module "default" running at: http://localhost:8080
INFO     2013-08-17 00:19:37,157 dispatcher.py:164] Starting module "hello" running at: http://localhost:8081
INFO     2013-08-17 00:19:37,160 admin_server.py:117] Starting admin server at: http://localhost:8000
INFO     2013-08-17 00:19:39,575 hello.py:9] Hello from the 'hello' module
INFO     2013-08-17 00:19:39,581 module.py:593] hello: "GET /_ah/start HTTP/1.1" 200 31

モジュールを呼び出すフロントエンドを呼び出すと、期待どおりに機能します。

$ curl "http://localhost:8080/send_hello/world"
backend response: 200 Hello from the 'hello' module!

モジュールを直接呼び出すと、期待どおりに動作します

$ curl "http://localhost:8081/hello/world"
Hello from the 'hello' module!

本番サーバーでのテストが失敗する

アプリを本番環境にロードする

$ appcfg.py update app.yaml hello.yaml

モジュールを呼び出すフロントエンドを呼び出します..そして404を取得します

$ curl "http://123456.myapp.appspot.com/send_hello/world"
backend response: 404
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Not Found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Not Found</h1>
<h2>The requested URL <code>/hello/world</code> was not found on this server.</h2>
<h2></h2>
</body></html>

モジュールを直接呼び出して 503 エラーを取得する

$ curl "http://hello.myapp.appspot.com/hello/world"

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>503 Server Error</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Server Error</h1>
<h2>The service you requested is not available yet.<p>Please try again in 30 seconds. </h2>
<h2></h2>
</body></html>

バージョン指定子を使用してモジュールを呼び出すと、404 エラーが発生します。

$ curl "http://123456.hello.myapp.appspot.com/hello/world"

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>404 Not Found</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Not Found</h1>
<h2>The requested URL <code>/hello/world</code> was not found on this server.</h2>
<h2></h2>
</body></html>

質問...

実稼働環境の manual_scaling インスタンスが実際の G​​oogle サーバーである実稼働環境サーバーで起動しないのはなぜですか? 「app.yaml」の手動スケーリング行をコメントアウトすると、アプリは本番環境で期待どおりに動作することに注意してください。

もう 1 つの手がかりは、Google App Engine コンソールに「hello」モジュールのログが表示されず、アクティブなインスタンスが表示されないことです。そして奇妙なことに、appcfg.py start hello.yamlそれはすでに実行されていると言います。

この質問に答えるもう 1 つの方法は、モジュールを使用した「手動スケーリング」の完全に機能する例を示すことです (Google のスニペットでは不十分です)。

4

1 に答える 1

6

私自身の問題を考え出した...

version: 123456.yaml ファイルの を に変更すると、本番環境version: v123456で期待どおりに動作します。

「manual_scaling」モジュール タイプの場合、バージョンに整数を使用することはサポートされていないようです。おそらく、特定のインスタンスの URL があいまいになります。

于 2013-08-24T00:28:21.443 に答える