经过一些重构之后,我们在应用程序中使用的objectify查询出现了问题。奇怪的是,即使我们恢复到原来的代码,问题仍然存在。
当应用程序启动时,使用Objectify从Datastore获取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本书的基本查询,但获得实际结果需要花费一生的时间。知道我怎么能进一步调查这个问题吗?
发布于 2016-11-07 14:46:54
发现问题了。我们在BookEntity的非args构造函数中保存了一些信息,因此对于从数据存储3中获取的每一本书,都为书中引用的其他实体进行了保存操作。
https://stackoverflow.com/questions/40463487
复制相似问题