首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google "manual_scaling“无法工作

Google "manual_scaling“无法工作
EN

Stack Overflow用户
提问于 2013-08-17 01:29:19
回答 1查看 1.6K关注 0票数 3

目前,我的设计有一个前端,通过URL获取与常驻后端对话。新设计将使用模块而不是后端。这是谷歌希望人们走的方向,所以这应该不难,但是让它在生产中运行已经困扰了我好几天了。"缩放“对我不起作用。"manual_scaling“在dev_appserver.py (1.8.3)中工作得很好,只是在生产中不起作用。我已经尽可能地简化了这个问题。这里有四个应该重复这个问题的文件:

源代码

app.yaml

代码语言:javascript
复制
api_version: 1
application: myapp
version: 123456
runtime: python27
threadsafe: true
handlers:
- url: /send_hello/.*
  script: send_hello.app
- url: /hello/.*
  script: hello.app

hello.yaml

代码语言:javascript
复制
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

hello.py

代码语言:javascript
复制
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

代码语言:javascript
复制
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)

使用开发服务器进行测试非常有效。

启动它,它运行得很好,您可以看到手动缩放实例启动。

代码语言:javascript
复制
$ 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

调用调用模块的前端,它按预期工作:

代码语言:javascript
复制
$ curl "http://localhost:8080/send_hello/world"
backend response: 200 Hello from the 'hello' module!

直接调用模块,它按预期工作。

代码语言:javascript
复制
$ curl "http://localhost:8081/hello/world"
Hello from the 'hello' module!

使用生产服务器进行测试失败

将应用程序加载到生产中

代码语言:javascript
复制
$ appcfg.py update app.yaml hello.yaml

调用调用模块的前端..。得到404

代码语言:javascript
复制
$ 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错误。

代码语言:javascript
复制
$ 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错误:

代码语言:javascript
复制
$ 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实例没有在生产服务器上启动,也就是实际的Google?请注意,如果您注释掉了"app.yaml“中的手动缩放行,该应用程序在生产环境中就会像预期的那样工作。

另一个线索是控制台没有显示"hello“模块的日志记录,也没有显示任何活动实例。奇怪的是,appcfg.py start hello.yaml说它已经在运行了。

回答这个问题的另一种方法是向我介绍一个完整的使用模块进行“手动缩放”的示例( Google的代码片段是不够的)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-24 00:28:21

解决了我自己的问题..。

将.yaml文件中的.yaml更改为version: v123456,并在生产中按预期工作。

在“manual_scaling”模块类型中,对版本使用整数似乎不受支持。也许它使特定实例的URL变得模棱两可。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18284237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档