AppEngine Datastore对象的手动序列化/反序列化 [英] manual serialization / deserialization of AppEngine Datastore objects

查看:143
本文介绍了AppEngine Datastore对象的手动序列化/反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以手动定义用于AppEngine Datastore的序列化逻辑?



我假设Google使用反射以通用方式执行此操作。这有效,但证明是相当缓慢的。我愿意编写(并维护)相当一些代码,以加快数据存储对象的序列化/反序列化(我有大对象,这会消耗相当一部分时间)。

(实现可以在SDK / google / appengine / datastore / entity_pb.py中找到)
如果您认为(de)序列化在您的案例中太慢,您可能有两个选择




  • 移至较低的DB API。在google.appengine.datastore中,有两个充分记录的ext.db和ext.ndb API旁边还有另一个API。这并不是所有的花式模型,并提供了一个简单的(有希望快速)字典式的API。这将使您的数据存储区布局与其他两个数据库API保持兼容。

  • 自己序列化对象,并将其存储在仅由文本字段组成的虚拟条目中。但是您可能需要将数据复制到基本条目中,因为您无法过滤/排序自行序列化文本中的数据。


Is it possible to manually define the logic of the serialization used for AppEngine Datastore?

I am assuming Google is using reflection to do this in a generic way. This works but proves to be quite slow. I'd be willing to write (and maintain) quite some code to speed up the serialization / deserialization of datastore objects (I have large objects and this consumes quite some percentage of the time).

解决方案

The datastore uses Protocol-Buffers internally, and there is no way round, as its the only way your application can communicate with the datastore. (The implementation can be found in the SDK/google/appengine/datastore/entity_pb.py) If you think, (de)serialization is too slow in your case, you probably have two choices

  • Move to a lower DB API. There's another API next to the two well-documented ext.db and ext.ndb APIs at google.appengine.datastore. This hasn't all the fancy model-stuff and provides a simple (and hopefully fast) dictionary-like api. This will keep your datastore-layout compatible with the other two DB APIs.
  • Serialize the object yourself, and store it in a dummy entry consisting just of a text-field. But you'll probably need to duplicate data into your base entry, as you cannot filter/sort by data inside your self-serialized text.

这篇关于AppEngine Datastore对象的手动序列化/反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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