How to get the size of a bin in Aerospike?

Viewed 672

In aerospike, when we do show sets we see something like:

+------------------+--------+---------+-------------------+------------+-------------------+-------------------+----------------+------------+
| disable-eviction | ns     | objects | stop-writes-count | set        | memory_data_bytes | device_data_bytes | truncate_lut   | tombstones |
+------------------+--------+---------+-------------------+------------+-------------------+-------------------+----------------+------------+
| "false"          | "test" | "310"   | "0"               | "byteData" | "25663706"        | "25680736"        | "358239062044" | "0"        |
| "false"          | "test" | "310"   | "0"               | "kwString" | "1076835"         | "1092352"         | "0"            | "0"        |
+------------------+--------+---------+-------------------+------------+-------------------+-------------------+----------------+------------+

This gives us an idea that the set byteData occupies around 25MB. Now, assume that the set byteData has two bins viz. binA and binB, then how can I get the sizes of the two bins?

2 Answers

Aerospike stores records - each record can have set name as a tag or metadata, and it can store bins. Schema is at record level and it will be whatever the user creates on a per record basis. So estimating "size of a bin in a set" is kind of a wrong ask. For example, in namespace n1, in set s1, I can add two records r1 and r2. r1 can have bins b1 and c1 and r2 can have bins b2 and c2. b1, c1, b2, c2 can be completely different datatypes from each other. Now, practically speaking, in a given set, a user will follow some kind of like schema across all records.

You can calculate the size of any record, including overhead, based on the data you are storing. See this link for details: https://docs.aerospike.com/docs/operations/plan/capacity/index.html but directly getting "size of a bin in a set" from Aerospike is not possible.

I could not find a direct way but there is a workaround. Workaround because this can not be known from the aql-prompt. I am using the Aerospike JAVA client and was able to find the size of the bin using the same.

Assume that you are inserting Strings in the bin, then all you need to do is:

Value value = new Value.StringValue(someString);
value.estimateSize(); //Store it in a list, and then sum up the sizes for 
//all the strings inserted in that bin to find the size of the bin

Reference for the answer - https://discuss.aerospike.com/t/how-to-get-record-size-in-aeropsike/2639

Other possible sub-classes other than StringValue are listed here

Related