如何计算Google App Engine中存储的实体的大小? [英] How do I calculate the size of an entity stored in Google App Engine?

查看:133
本文介绍了如何计算Google App Engine中存储的实体的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有简单的方法来计算存储在App Engine中的实体的大小?我想知道一个特定实体与实体大小的1 MB上限有多接近。

解决方案

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屋!

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