如何计算Google App Engine中存储的实体的大小? [英] How do I calculate the size of an entity stored in Google App Engine?
问题描述
App引擎将每个实体存储为 protobuf 。您可以使用 db.model_to_protobuf()函数#model_to_protobufrel =noreferrer> here 手动将实体转换为protobuf,然后使用标准的 len()
方法来确定它的大小(以字节为单位) 。
示例用法:
from google.appengine.ext import db
sz_in_bytes = len(db.model_to_protobuf(some_entity).Encode())
更新ndb
Kekito在下面的评论中指出,对于 ndb
实体需要一个不同的方法(谢谢Kekito!):
$ p $ len $(some_entity._to_pb()。Encode())
Is there an easy way to calculate the size of an entity stored in App Engine? I would like to know how close a particular entity is to hitting the 1 MB upper limit on entity size.
App engine stores each entity as a protobuf. You can use the db.model_to_protobuf()
function described here to manually convert your entity into a protobuf and then use the standard len()
method to determine its size in bytes.
Example usage:
from google.appengine.ext import db
sz_in_bytes = len(db.model_to_protobuf(some_entity).Encode())
Update for ndb
Kekito points out in the comments below that for ndb
entities a different approach is needed (Thanks Kekito!):
len(some_entity._to_pb().Encode())
这篇关于如何计算Google App Engine中存储的实体的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!