增加 Google App Engine 上的模型数量会影响性能吗?

发布于 2024-09-18 03:54:57 字数 230 浏览 9 评论 0原文

我在大学里制作了一个 Google App Engine 应用程序作为课堂项目。现在我需要对其进行优化以将其用于商业用途。

如今,代码非常慢。它只有很少的模型,每个模型都有很多属性。 在重写模型代码之前,我需要知道如果增加模型数量,即增加解耦,我的应用程序是否会更快。直到什么时候我应该考虑将模型划分为其他模型?

另一个问题是,如果解耦对性能产生积极影响,那么模型中的属性数量是否与从数据存储中获取它的时间成正比?

I made a Google App Engine application as a class project in my university. Now I need to optimize it to use it commercially.

Nowadays, the code is very slow. It has only few Models with many properties in each.
Before rewriting the Models code, I need to know if my application will be faster if I increase the number of Models, i.e. increase decoupling. And until what point should I consider dividing Models in other Models?

Other question, if decoupling positively affects performance, is the number of properties in a Model directly proportional to the time to fetch it from datastore?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杆小烟枪 2024-09-25 03:54:57

现在,代码非常慢。它
只有很少的模型有很多
每个属性。

获取/放置大对象

由于数据存储区 API 只能放置或获取一个对象(而不是单个字段),因此每次您为数据存储区获取对象时,无论您是否要访问,它都会获取其所有字段到那时是否使用它们。当我们将对象写回数据存储时,这种效果会更强,即使您更改对象中的单个字段,它也必须写入所有内容。 (写入成本高于读取)

在我进一步说之前:模型的扩散应该遵循您的读取和写入模式。

为了实用并举一个例子,假设我正在对博客上的帖子进行建模,其中每个字段都有一个 title、一个 date 和一个 body (我们可以正确地假设它比其他字段大得多)。在直接对象建模中,我将这三个字段放在一个类BlogPost中,但每次我只想读取< code>titles(比如简单地显示帖子列表并构建帖子的链接),或者只是更新日期

class BlogPost {
String title; String body; long date; }

因此,我们可以做的是创建一个类 Body 来保存 body,并在 BlogPost 中保留对其的引用(一个键)。

class BlogPost {
String title;
Key<Body> body;
long date;
}

class Body {
String body;
}

轻量级有助于高效的跨端序列化

如果我决定序列化它并通过网络发送它(例如将其发送到网络),这也会使 BlogPost 类更加轻量级浏览器(在 JavaScript 中使用),例如 GWT。

是否增加模型数量
Google App Engine 会影响性能吗?

来自尼克·约翰逊的回答:

不,添加额外的模型不会
影响性能。

Nowadays, the code is very slow. It
has only few Models with many
properties in each.

Getting/Putting big objects

Since the datastore API can only put or get an object (as opposed to individual fields), each time you fetch an object for the datastore it fetches all its fields regardless if you are going to use them all at that point or not. This effect will be stronger when we write the object back to the datastore, it has to write everything even when you alter a single field in the object. (writes cost more than reads)

Before I say anything further: the proliferation of models should follow your pattern of reads and writes.

To be practical and give an example, say I am modeling the posts on a blog, where each would have a title, a date and a body (which we will rightfully assume as being much bigger than the other fields). In the straightforward object modeling, I'd have those three fields in a single class BlogPost, but I am penalized for the whole object each time I just want to read the titles (say to simply display a list of posts and construct links to the posts), or just to update the dates.

class BlogPost {
String title; String body; long date; }

So what one can do is create a class Body that would hold body, and keep a reference (a key) to it inside BlogPost.

class BlogPost {
String title;
Key<Body> body;
long date;
}

class Body {
String body;
}

Lightweight makes for efficient cross-side serialization

This also makes the BlogPost class more lightweight if I decide to serialize it and send it over the wire, e.g to send it to the web browser (to be used in JavaScript), with GWT for example.

Does increasing the number of models on
Google App Engine affects performance?

Answer from Nick Johnson:

No, adding additional models will not
impact performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文