Objectify 查询非常慢(Google 数据存储)
Objectify queries are very slow (Google Datastore)
经过一些重构后,我们在应用程序中使用的对象化查询出现了问题。 st运行ge 的事情是,即使我们恢复到原始代码,问题仍然存在。
应用程序启动时,会使用 Objectify 从数据存储中获取 250 本书。缓存已启用并且似乎正在运行。
问题是它需要大约 50 - 60 秒才能得到结果,因此有时 http 请求会被终止。我们以前从未遇到过这个问题,我们找不到答案。
如果我在 Google 数据存储控制台中 运行 一个类似 "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 本书,但它需要一生才能获得实际结果。知道如何进一步调查这个问题吗?
发现问题。我们在 BookEntity 的非参数构造函数中保留了一些信息,因此对于从数据存储区获取的每本书,都会为从书中引用的其他一些实体进行 3 次保存操作。
经过一些重构后,我们在应用程序中使用的对象化查询出现了问题。 st运行ge 的事情是,即使我们恢复到原始代码,问题仍然存在。
应用程序启动时,会使用 Objectify 从数据存储中获取 250 本书。缓存已启用并且似乎正在运行。 问题是它需要大约 50 - 60 秒才能得到结果,因此有时 http 请求会被终止。我们以前从未遇到过这个问题,我们找不到答案。 如果我在 Google 数据存储控制台中 运行 一个类似 "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 本书,但它需要一生才能获得实际结果。知道如何进一步调查这个问题吗?
发现问题。我们在 BookEntity 的非参数构造函数中保留了一些信息,因此对于从数据存储区获取的每本书,都会为从书中引用的其他一些实体进行 3 次保存操作。