如何避免 GoogleAppEngine DataStore 延迟?

发布于 12-25 05:08 字数 771 浏览 2 评论 0原文

我是 App Engine 的新手,编写了一个示例应用程序。如果我创建或更新实体:

Entity record = new Entity(...);
... set properties
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(record);

然后重定向到显示新实体或更新实体的页面

resp.sendRedirect("MainPage.jsp");

,其中执行以下代码

DatastoreService datastore =
DatastoreServiceFactory.getDatastoreService();   
Query query = new Query(...).addSort(..., Query.SortDirection.DESCENDING); 
List<Entity> entities = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(20));

新记录不在列表中。页面已更新(如显示的时间戳所示),但只有在刷新页面时延迟最多几秒后才会显示新记录或现有记录的修改。

如何避免这种情况? DataStore 可能不适合这样的事情吗?

我正在使用 GAE 的 Eclipse 本地测试环境和 Windows XP 64。

I am new to App Engine and wrote a sample App. If i create or update a entity:

Entity record = new Entity(...);
... set properties
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(record);

and then redirect to a page where the new or updated entity is displayed

resp.sendRedirect("MainPage.jsp");

where the following code is executed

DatastoreService datastore =
DatastoreServiceFactory.getDatastoreService();   
Query query = new Query(...).addSort(..., Query.SortDirection.DESCENDING); 
List<Entity> entities = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(20));

The new record is not in the list. The page is updated (as shown by a timestamp displayed), but the new record or a modification of a existing record is shown only after a delay of up to some seconds when i refresh the page.

How can this be avoided?
Is the DataStore possible not suited for such a thing?

I am using the Eclipse local test environment from GAE with Windows XP 64.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煞人兵器2025-01-01 05:08:53

是的,这称为“最终一致性”,是 HRD 的默认更新模型(现在所有新实例上的默认值)。

因此,放置一个实体然后查询它可能不会返回(事件一致性),但是放置它然后获取它(通过键获取)将立即返回(强一致性)。

解决方案是:

  1. 使用主从数据存储,或者
  2. 如果可能,重写代码以使用 get 而不是查询。

此外,本地开发服务器仅用于测试,其行为与生产实例并不完全相同,因此您应该始终(最终)在生产上进行测试。

Yeah, this is called "eventual consistency" and is the default update model for HRD (now default on all new instances).

So putting an entity and then querying for it might not get is back (evental consistency), but putting it and then getting it (get via a key) will get it back immediately (strong consistency).

Solution is either to:

  1. Use Master-slave datastore, or
  2. If possible, rewrite code to use get instead of queries.

Also, local dev server is only for testing and does not behave exactly as production instances, so you should always (eventually) test on production.

夏夜暖风2025-01-01 05:08:53

由于您在 GAE 上运行,因此最好的选择是使用其 Memcache 用于短期检索(您仍然需要将内容放入 DataStore 中以实现持久性)。

Since you are running on GAE, your best option is to use its Memcache for short-term retrieval (you still need to put stuff in the DataStore for persistence).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文