Google App Engine上的简单数据库查询占用大量CPU时间 [英] Simple DB query on Google App Engine taking a lot of CPU time

查看:140
本文介绍了Google App Engine上的简单数据库查询占用大量CPU时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Google App Engine和Python相当陌生,但我只是用它发布了我的第一个真实世界的网站。但是现在我遇到了一条使用比其他路径显着更多CPU(和API CPU)时间的路径问题。我已经将它缩小到一个数据存储区获取导致问题: Carvings.all()。fetch(1000)



在App Engine仪表板下,它非常可靠地为每条到该路径的请求报告1040cpu_ms 846api_cpu_ms。似乎这可能是我的客户在一般情况下经历过的一些无反应的原因。



所以我无法弄清楚什么是如此昂贵这个查询。这里是相关的数据模型:

pre code> class Carving(db.Model):
title = db.StringProperty = True)
reference_number = db.StringProperty()
main_category = db.StringProperty()
sub_category = db.StringProperty()
image = db.ReferenceProperty(CarvingImage)
description = db.TextProperty()
price = db.FloatProperty()
size = db.StringProperty()
material = db.StringProperty()
added_at = db。 DateTimeProperty(auto_now_add = True)
modified_at = db.DateTimeProperty(auto_now = True)

应用程序中的其他地方,当我从数据存储拉这个模型,我做了更多的过滤,我想这就是为什么他们没有造成任何麻烦。但是这个模型的实体总数刚好在90以上,我无法想象为什么这么贵。

解决方案


  • Memcache,如果你还没有,特别是如果一次又一次提取相同的雕刻。如果你总共只有90个,我想他们都会很快进入缓存,然后你应该变成金。

  • 你需要所有的雕刻的属性?例如,如果您只是显示雕刻列表,则可以有一个单独的实体,类似于CarvingSummary,它只具有一些属性。这意味着你的模式是非规范化的,但有时候这就是你为速度付出的代价。




另外,我假设这不是用户总是打的第一页?如果是这样的话,它可能是云计算出一个新实例。

I'm fairly new to Google App Engine and Python, but I did just release my first real-world site with it. But now I'm getting problems with one path that is using significantly more CPU (and API CPU) time than the other paths. I've narrowed it down to a single datastore fetch that's causing the problem: Carvings.all().fetch(1000)

Under the App Engine dashboard it's reporting "1040cpu_ms 846api_cpu_ms" pretty reliably for each request to that path. It has seemed like this may be the source to some unresponsiveness that my client has experienced with the site in general.

So I can't figure out what is so expensive about this query. Here is the related data model:

class Carving(db.Model):
    title = db.StringProperty(required=True)
    reference_number = db.StringProperty()
    main_category = db.StringProperty()
    sub_category = db.StringProperty()
    image = db.ReferenceProperty(CarvingImage)
    description = db.TextProperty()
    price = db.FloatProperty()
    size = db.StringProperty()
    material = db.StringProperty()
    added_at = db.DateTimeProperty(auto_now_add=True)
    modified_at = db.DateTimeProperty(auto_now=True)

In other places in the app when I pull this model from the datastore I do more filtering and I guess that's why they aren't causing any troubles. But the total number of entities for this model is just above 90 and I just can't imagine why this is so expensive.

解决方案

  • Memcache, if you haven't already, and especially if the same carvings are going to be fetched again and again. If you only have 90 total, I would imagine they would all be in the cache pretty quickly, and then you should be golden.

  • Do you need all the properties of the Carvings? For example, if you're just displaying a list of carvings, you could have a separate Entity that was something like CarvingSummary that only had a few properties. This would mean your schema was denormalized, but sometimes that's the price you pay for speed.

Also, I'm assuming this is not the first page the user will always hit? If that were the case it could be the cloud spinning up a a new instance.

这篇关于Google App Engine上的简单数据库查询占用大量CPU时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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