How to get python object size in bytes in Google AppEngine app?

I need to calculate the sizes of some python objects, so I can split them and save them in memcache without size limits.

' sizeof ()' does not seem to be present in python objects in the GAE environment, and sys.getsizeof () is also not available.

GAE itself clearly checks the dimensions behind the scenes to ensure compliance. Any ideas on how to do this? Thanks.

+4
source share
1 answer

memcache internally and invariably uses pickle and saves the resulting string, so you can check it with len(pickle.dumps(yourobject, -1)) . Note that sys.getsizeof (which requires 2.6 or better, which is why it is missing from GAE) doesn't really help you at all:

 >>> import sys >>> sys.getsizeof(23) 12 >>> import pickle >>> len(pickle.dumps(23, -1)) 5 

since the size of the serialized brine of the object can be very different from the size of the object in memory, as you can see (therefore, I think you should feel grateful to GAE for not offering sizeof, which would lead you astray -.)

+8
source

All Articles