使用 dev_appserver.py 在不同端口上运行多个服务 [英] Running multiple services using dev_appserver.py on different ports

查看:37
本文介绍了使用 dev_appserver.py 在不同端口上运行多个服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有休息端点和网络端点的应用程序.

I have an application which has rest end point and web end point.

我想使用 dev_appserver.py 在本地同时运行 REST 和 WEB 服务

I want to run both REST and WEB service locally using dev_appserver.py

我已经尝试了以下

dev_appserver.py rest_app.yaml --port=5010 --admin_port=8000

dev_appserver.py web_app.yaml --port=5011 --admin_port=8001

我在我的一项服务(休息服务)上看到以下错误

I see the following error on one of my services (rest service)

`OperationalError: database is locked`

我是否需要做任何特别的事情来确保这两个服务都可以无条件地读/写共享数据库(或类似的坏事!!)

Do I have to do anything special to make sure both those services can read/write to a shared database without any conditions (or similar bad things !!)

我的目标是在本地运行多个服务(在本例中为 rest 和 web),并且这些服务应该提供数据.执行此操作的最佳方法是什么(在本地使用 dev_appserver.py)和在 GAE 本身中(稍后我将应用程序推送到 GAE 时会出现这种情况:D)

My goal is to run multiple services (rest and web in this case) locally and those services should data. What is the best way to do this (using dev_appserver.py locally) and in GAE itself (this will come later when I push my application to GAE :D )

推荐答案

您收到 OperationalError: database is locked 的原因是 2 dev_appserver.py 实例将在尝试访问相同的数据库本地存储目录时发生冲突,默认情况下,该目录是根据应用的名称确定的 - 同一应用的 2 个服务相同.

The reason for which you're getting OperationalError: database is locked is that the 2 dev_appserver.py instances will collide trying to access the same database local storage dir, which by default is determined based on the app's name - identical for 2 services of the same app.

避免此类冲突的一种方法是还指定本地存储目录,使用 dev_appserver.py--storage_path 可选参数(您可以通过 <代码>dev_appserver.py --help):

One way to avoid such collision is to also specify the local storage directory, using dev_appserver.py's --storage_path optional argument (which you can see via dev_appserver.py --help):

--storage_path PATH   path to the data (datastore, blobstore, etc.)
                      associated with the application. (default: None)

然而,使用 2 个不同的存储路径可能会产生意想不到的结果 - 如果您的服务引用该存储中应该是相同的信息,它们可能会看到不同的值.

However using 2 different storage paths may produce unexpected results - if your services reference what should be the same information in that storage they might see different values.

dev_appserver.py 与同一应用程序的多个服务一起使用的正确方法是通过单个 dev_appserver.py 实例运行所有服务,这将分配不同的每个服务的端口.

The proper way of using dev_appserver.py with multiple services of the same app is to run all the services through a single dev_appserver.py instance, which will allocate different ports to each service.

例如,我有一个包含 3 个服务并使用调度文件的应用程序.这就是我从应用程序目录调用开发服务器的方式,该目录是 3 个服务目录的父目录(调度文件必须是 .yaml 文件参数列表中的第一个,我总是遵循它与默认模块的一个,在我的情况下 main/main.yaml):

For example I have an app with 3 services and using a dispatch file. This is how I invoke the dev server, from the app dir which is the parent dir of 3 service dirs (the dispatch file must be the 1st one in the list of .yaml file args and I always follow it with the default module's one, in my case main/main.yaml):

/usr/bin/python2.7 /usr/local/google_appengine/dev_appserver.py --host 0.0.0.0 --log_level=debug dispatch.yaml main/main.yaml buildin/buildin.yaml apartci/apartci.yaml

这是 devserver 自动分配每个服务侦听的端口的方式,在服务器启动时显示:

And this is how the devserver automatically assigns the ports each service listens to, displayed when the server starts:

INFO     2016-11-18 14:20:53,329 api_server.py:205] Starting API server at: http://localhost:40310
INFO     2016-11-18 14:20:53,330 dispatcher.py:185] Starting dispatcher running at: http://0.0.0.0:8080
INFO     2016-11-18 14:20:53,345 dispatcher.py:197] Starting module "default" running at: http://0.0.0.0:8081
INFO     2016-11-18 14:20:53,353 dispatcher.py:197] Starting module "buildin" running at: http://0.0.0.0:8082
INFO     2016-11-18 14:20:53,361 dispatcher.py:197] Starting module "apartci" running at: http://0.0.0.0:8083
INFO     2016-11-18 14:20:53,362 admin_server.py:116] Starting admin server at: http://localhost:8000

这篇关于使用 dev_appserver.py 在不同端口上运行多个服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆