【问题标题】:Objectify queries are very slow (Google Datastore)对象化查询非常慢(谷歌数据存储)
【发布时间】:2016-11-07 10:57:22
【问题描述】:

经过一些重构后,我们在应用程序中使用的对象化查询遇到了问题。奇怪的是,即使我们恢复到原始代码,问题仍然存在。

当应用程序启动时,会使用 Objectify 从数据存储中获取 250 本书。缓存已启用并且似乎正在工作。 问题是获得结果大约需要 50 - 60 秒,因此有时 http 请求会被终止。我们以前从未遇到过这个问题,我们无法找到答案。 如果我在 Google Datastore 控制台中运行“select * from BookEntity order by creationDate desc limit 250”之类的查询,则需要 5 - 7 秒而不是更多。

在重构之前,书本实体看起来像这样:

@Index
@Entity
@Cache
public class BookEntity {
    @Index
    public String title_name;
    @Index
    public String author_name;
    public String isbn;
    public int number_of_pages;
    public Ref<PdfEntity> book_pdf;
}

现在是这样的:

@Index
@Entity
@Cache
public class BookEntity {
    @Index
    @AlsoLoad("title_name")
    private String titleName;

    @Index
    @AlsoLoad("author_name")
    private String authorName;

    private String isbn;

    @AlsoLoad("number_of_pages")
    private int numberOfPages;

    @AlsoLoad("book_pdf")
    private Ref<PdfEntity> bookPdf;

    // getters and setters for the fields because now they are private
}

这只是一个示例,但实际上它有大约 20 个字段。 为了将架构迁移到字段名称,我在 GAE 中运行了一个任务,该任务加载并再次保存了所有 BookEntity 实体。

这个例子可以扩展到应用程序中使用的所有实体,但是这本书是表现最差的。尽管查询中没有任何变化,而且我们正在讨论一个基本查询,它按 creationDate 获取最新的 250 本书,但要获得实际结果需要生命周期。知道如何进一步调查此问题吗?

【问题讨论】:

    标签: google-app-engine google-cloud-datastore objectify


    【解决方案1】:

    发现问题。我们在 BookEntity 的非参数构造函数中保留了一些信息,因此对于从数据存储中获取的每本书,对从书中引用的其他一些实体进行了 3 次保存操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      • 2012-11-20
      • 1970-01-01
      • 2017-12-24
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      相关资源
      最近更新 更多