Objectify查询非常慢(Google Datastore)

时间:2016-11-07 10:57:23

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

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

当应用程序启动时,使用Objectify从数据存储区中提取250本书。缓存已启用,似乎正在运行。 问题是获得结果需要大约50-60秒,因此有时会杀死http请求。我们以前从未遇到过这个问题,我们无法找到答案。 如果我运行类似&#34的查询;请通过creationDate desc limit 250"从BookEntity订单中选择*。在Google Datastore控制台中,它花了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本书的基本查询,但获取实际结果需要一生。知道如何进一步调查这个问题吗?

1 个答案:

答案 0 :(得分:1)

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