Is there a performance gain from defining routes in app.yaml versus one large mapping in a WSGIApplication in AppEngine?(在 app.yaml 中定义路由与在 AppEngine 中的 WSGIApplication 中定义一个大型映射相比,是否有性能提升?)
问题描述
这涉及在 app.yaml 中使用一个网关"路由,然后在 WSGIApplication 中选择 RequestHandler.
This involves using one "gateway" route in app.yaml and then choosing the RequestHandler in the WSGIApplication.
- url: /.*
script: main.py
main.py
from google.appengine.ext import webapp
class Page1(webapp.RequestHandler):
def get(self):
self.response.out.write("Page 1")
class Page2(webapp.RequestHandler):
def get(self):
self.response.out.write("Page 2")
application = webapp.WSGIApplication([
('/page1/', Page1),
('/page2/', Page2),
], debug=True)
def main():
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
<小时>
场景 2:
这涉及在 app.yaml 中定义两个路由,然后为每个路由定义两个单独的脚本(page1.py 和 page2.py).
Scenario 2:
This involves defining two routes in app.yaml and then two separate scripts for each (page1.py and page2.py).
- url: /page1/
script: page1.py
- url: /page2/
script: page2.py
page1.py
from google.appengine.ext import webapp
class Page1(webapp.RequestHandler):
def get(self):
self.response.out.write("Page 1")
application = webapp.WSGIApplication([
('/page1/', Page1),
], debug=True)
def main():
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
page2.py
from google.appengine.ext import webapp
class Page2(webapp.RequestHandler):
def get(self):
self.response.out.write("Page 2")
application = webapp.WSGIApplication([
('/page2/', Page2),
], debug=True)
def main():
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
<小时>
问题
每种模式的优缺点是什么?一个比另一个快得多吗?
Question
What are the benefits and drawbacks of each pattern? Is one much faster than the other?
推荐答案
唯一的性能影响与模块的加载有关:模块在第一次使用时加载到实例上,拆分事物需要更少的模块加载到在新实例上提供页面.
The only performance implication relates to the loading of modules: Modules are loaded on an instance when they're first used, and splitting things up requires fewer module loads to serve a page on a new instance.
不过,这非常简单,因为您可以轻松地让处理程序脚本按需动态加载所需的模块 - 这就是许多常见框架已经做的事情.
This is pretty minimal, though, as you can just as easily have the handler script dynamically load the needed module on-demand - and that's what many common frameworks already do.
一般来说,app.yaml 路由是为不同组件或应用程序之间的路由而设计的.例如,remote_api 和 deferred 都有自己的处理程序.因此,为您的应用定义一个处理其他所有内容的处理程序是完全合理的.
In general, app.yaml routing is designed for routing between distinct components or applications. For example, remote_api and deferred both have their own handlers. It's perfectly reasonable, therefore, to have a single handler defined for your app that handles everything else.
这篇关于在 app.yaml 中定义路由与在 AppEngine 中的 WSGIApplication 中定义一个大型映射相比,是否有性能提升?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 app.yaml 中定义路由与在 AppEngine 中的 WSGIApplication 中定义一个大型映射相比,是否有性能提升?
基础教程推荐
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
