简体   繁体   English

Google AppEngine实体组大小和最终一致性

[英]Google AppEngine Entity group sizes and eventual consistency

I have a shopping cart application that contains users, accounts, orders, order lines etc entities. 我有一个购物车应用程序,其中包含用户,帐户,订单,订单行等实体。

Many of my entities belong to the account entity eg an account has many orders, an order has many order lines and an order line has as many-to-many shipments relationship. 我的许多实体属于帐户实体,例如,帐户有许多订单,订单有许多订单行,订单行有多对多的货运关系。 The account also has many users who can view the account's child entities. 该帐户还有许多用户可以查看帐户的子实体。

The documentation recommends keeping entity groups no larger than a single user's worth of data: https://developers.google.com/appengine/docs/python/datastore/entities 文档建议保持实体组不超过单个用户的数据: https//developers.google.com/appengine/docs/python/datastore/entities

I'm concerned that an entity group for an account could grow to a size which becomes unscalable. 我担心帐户的实体组可能会增长到不可扩展的大小。 An account could grow to 100,000 orders with hundreds of thousands of child entities. 一个帐户可以增长到100,000个订单,其中包含数十万个子实体。

I have two questions: 我有两个问题:

1.) If I don't use ancestors do I simply have to accept that if one user edits an entity it may not be updated for a few seconds? 1.)如果我不使用祖先,我只需要接受,如果一个用户编辑实体,它可能几秒钟内不会更新?

2.) If I do use ancestors, what will happen if an account has many users all creating/editing/deleting within the same entity group throughout the day? 2.)如果我使用祖先,如果一个帐户有多个用户全天在同一个实体组内创建/编辑/删除会怎样? Will some transactions get blocked? 某些交易会被封锁吗?

Seems like the entity group here should be the order plus its items, not the account. 似乎这里的实体组应该是订单加上其项目,而不是帐户。

There is a limit of one update per second per entity group, so if you defined the group at the account level and you do have multiple users updating a single user constantly, some will fail. 每个实体组每秒更新一次,因此如果您在帐户级别定义了该组,并且您确实有多个用户不断更新单个用户,则有些用户将会失败。 That's much less likely to happen if you define it as the order. 如果将其定义为订单,则发生这种情况的可能性要小得多。

I would however strongly recommend that you do use an entity group for the order itself. 但是,我强烈建议您为订单本身使用实体组。 You definitely wouldn't want there to be possible discrepancies in what the user sees - or worse, pays for - within a single order. 您绝对不希望在一个订单中用户看到的内容可能存在差异 - 或者更糟糕的是,付费。

The only issue with doing things this way is that a new order might not be shown in the list of orders for an account immediately after it is created. 以这种方式处理的唯一问题是,在创建帐户后,新订单可能不会立即显示在帐户的订单列表中。 To get round that you might use memcache, or potentially have a separate entity storing the list of orders for the user with a manually-specified key that you can get directly rather than querying - eg using the customer's account number as the key name. 为了解决这个问题,您可以使用memcache,或者可能有一个单独的实体,用手工指定的密钥存储用户的订单列表,您可以直接获取而不是查询 - 例如使用客户的帐号作为密钥名称。 Since gets are guaranteed to be consistent, this would always be up to date. 由于获得保证一致,这将始终是最新的。

  1. Yes, but eventual consistency affects only queries. 是的,但最终的一致性仅影响查询。 If you edit the data and then GET it, the changes will be visible. 如果您编辑数据然后获取数据,则可以看到更改。

  2. No, there is no mention of size limitations or transaction blocking on entity groups mentioned in the docs. 不,没有提及文档中提到的实体组的大小限制或事务阻止。 The limitation that applies is write throughput per entity group: docs state a limit of 1 write/second per entity group (in practice I see about 5 writes/sec). 适用的限制是每个实体组的写入吞吐量:docs表示每个实体组的写入/秒限制为1(实际上我看到大约5次写入/秒)。 But this should not be an issue if you design your entity group to be per-user. 但如果您将实体组设计为每个用户,这不应该是一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM