我如何避免GoogleAppEngine DataStore延迟? [英] How can i avoid GoogleAppEngine DataStore delay?

查看:112
本文介绍了我如何避免GoogleAppEngine DataStore延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 实体记录=新实体(...); 
...设置属性
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(record);

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

  resp.sendRedirect(MainPage.jsp); 

其中执行以下代码

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

新记录不在列表中。页面被更新(如显示的时间戳所示),但是新的记录或现有记录的修改仅在我刷新页面时延迟几秒钟才显示。



这怎么能避免?
DataStore可能不适合这样的事情吗?

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

解决方案

是的,这叫做最终一致性,并且是HRD的默认更新模型(现在是所有新实例的默认更新模式)。因此,放置一个实体然后查询它可能不会返回(事件一致性),但是将其放回并获取它(通过键获取)会立即返回(强一致性)。



解决方案是:


  1. 使用主从数据存储或

  2. 如果可能,重写代码以使用获取而不是查询。

另外,本地开发服务器仅用于测试,并不像生产实例那样运行,所以您应该始终(最终)对生产进行测试。

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.

解决方案

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.

这篇关于我如何避免GoogleAppEngine DataStore延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆