I am trying to save timeseries data into MongoDB using pymongo. However the average object size is 14 bytes, while I need to store it in 4 bytes.
The issue is Python pre-allocates variables to 24 bytes (or based on the variable size, larger) , and after conversion in pymongo is a bloated collection.
For example :
x=1
sys.getsizeof(x)
24 Bytes
x=1000**1000
sys.getsizeof(x)
1356 Bytes
The above example is an illustration, I am using smaller sizes, typically 32 bit for voltages current etc How can I ensure 4 byte fit to python variables and a smaller mongoDB timeseries collection
The runtime size of the Python object is mostly irrelevant here - specially for small integers - since what get stored is a bson representation of the object not - obviously - the Python object itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With