App Engine:很少有大脚本还是有很多小脚本? [英] App Engine: Few big scripts or many small ones?

查看:17
本文介绍了App Engine:很少有大脚本还是有很多小脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个我想在 App Engine 上托管的网站.我的 App Engine 脚本是用 Python 编写的.现在假设您可以在我的网站上注册并拥有用户资料.现在,用户配置文件非常广泛,有 50 多个不同的 ndb 属性(仅举个例子).

I am working on a website that I want to host on App Engine. My App Engine scripts are written in Python. Now let's say you could register on my website and have a user profile. Now, the user Profile is kind of extensive and has more than 50 different ndb properties (just for the sake of an example).

如果用户想要编辑他的记录(他可以在某种程度上这样做),他可以通过我的网站向应用引擎后端发送请求.

If the user wants to edit his records (which he can to some extend) he may do so through my website send a request to the app engine backend.

配置文件是部分的方式,通常大约 5 到 10 个属性属于页面的一个小子部分或容器.在服务器端,我会有多个小脚本来处理编辑整个配置文件的小部分.例如,一个脚本会更新地址信息",另一个脚本会更新兴趣"和关于我"的文本.这样我最终得到了 5 个左右的脚本.优点是每个脚本都易于维护,并且只做一件特定的事情.但我不知道这样的事情是否明智的表现.因为如果我在页面的其余部分保持这个习惯,我最终可能会得到大约 100 个或更多不同的 .py 脚本和一个非常大的 app.yaml,我不知道它们在谷歌服务器上的缓存效率如何.

The way the profile is section, often about 5 to 10 properties fall into a small subsection or container of the page. On the server side I would have multiple small scripts to handle editing small sections of the whole Profile. For example one script would update "adress information", another one would update "interests" and an "about me" text. This way I end up with 5 scripts or so. The advantage is that each script is easy to maintain and only does one specific thing. But I don't know if something like this is smart performance wise. Because if I maintain this habbit for the rest of the page I'll probably end up with about 100 or more different .py scripts and a very big app.yaml and I have no idea how efficiently they are cached on the google servers.

所以 tl;dr:

在我的 App Engine 后端执行小任务的许多小型后端脚本是一个好主意,还是我应该使用一些可以处理一系列不同任务的脚本?

Are many small backend scripts to perform small tasks on my App Engine backend a good idea or should I use few scripts which can handle a whole array of different tasks?

推荐答案

每次启动应用程序实例时都必须加载一个大脚本,这可能会影响实例启动时间、启动每个请求的响应时间实例和实例的内存占用.但它可以立即处理任何请求,不需要加载额外的代码.

A single big script would have to be loaded every time an instance for your app starts, possibly hurting the instance start time, the response time of every request starting an instance and the memory footprint of the instance. But it can handle any request immediately, no additional code needs to be loaded.

多个较小的脚本可以按需延迟加载,在您的应用启动后,提供可能对某些应用有吸引力的优势:

Multiple smaller scripts can be lazy-loaded, on demand, after your app is started, offering advantages maybe appealing to some apps:

  • 主应用程序/模块脚本可以保持较小,从而缩短实例启动时间
  • 应用程序的内存占用可以保持更小,延迟加载文件中的处理程序代码在有此类处理程序的请求之前不会加载 - 对于很少使用的处理程序很有趣
  • 对于需要加载处理程序代码的请求,响应时间的额外延迟较小,因为只需要加载一个较小的脚本.

当然,缺点是一些请求会由于加载处理程序脚本而具有比平常更长的延迟:在最坏的情况下,受影响的请求数是每个实例的脚本数一生.

Of course, the disadvantage is that some requests will have longer than usual latencies due to loading of the handler scripts: in the worst case the number of affected requests is the number of scripts per every instance lifetime.

更新用户配置文件不是经常做的事情,我认为这是一个很少使用的功能,因此将其处理程序放在一个单独的文件中看起来很有吸引力.将其拆分为每个文件的一个处理程序 - 我发现 可能 有点极端.这真的取决于你,你更了解你的应用和你的风格.

Updating a user profile is not something done very often, I'd consider it a rarely used piece of functionality, thus placing its handlers in a separate file looks appealing. Splitting it into one handler per file - I find that maybe a bit extreme. It's really is up to you, you know better your app and your style.

从 GAE(缓存)基础设施的角度来看 - 文件配额是 10000 个文件,我不会担心只有大约 100 个文件.

From the GAE (caching) infra perspective - the file quota is 10000 files, I wouldn't worry too much with just ~100 files.

这篇关于App Engine:很少有大脚本还是有很多小脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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