Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ItemSize in DynamoDB

I'm trying to compute the size of an item in dynamoDB and I'm not able to understand the definition.

The definition I found : An item size is the sum of lengths of its attribute names and values (binary and UTF-8 lengths). So it helps if you keep attribute names short.

Does it mean that if I put a number in the database, example: 1 it'll take the size of an int? a long? a double? Will it take the same amount of space than 100 or 1000000 or it'll take only the size of the corresponding binary?

And what is the computing for String?

Is there someone that knows how to compute it?

Thank you

like image 600
Mike Avatar asked Jan 24 '12 14:01

Mike


People also ask

How does DynamoDB calculate item size?

The size of a number is approximately (length of attribute name) + (1 byte per two significant digits) + (1 byte). A binary value must be encoded in base64 format before it can be sent to DynamoDB, but the value's raw byte length is used for calculating size.

Can I store JSON object in DynamoDB?

PutItem and JSON documentsYou can store a JSON document as an attribute in a DynamoDB table. To do this, use the withJSON method of Item . This method parses the JSON document and maps each element to a native DynamoDB data type.

Can I store images in DynamoDB?

If you wanted to store an image of each product that was too large to fit in an item, you could store the images in Amazon S3 instead of in DynamoDB. When implementing this strategy, keep the following in mind: DynamoDB doesn't support transactions that cross Amazon S3 and DynamoDB.


1 Answers

That's a non trivial topic indeed - You already quoted the somewhat sloppy definition from the Amazon DynamoDB Data Model:

An item size is the sum of lengths of its attribute names and values (binary and UTF-8 lengths).

This is detailed further down the page within Amazon DynamoDB Data Types a bit:

  • String - Strings are Unicode with UTF8 binary encoding.
  • Number - Numbers are positive or negative exact-value decimals and integers. A number can have up to 38 digits of precision after the decimal point, and can be between 10^-128 to 10^+126. The representation in Amazon DynamoDB is of variable length. Leading and trailing zeroes are trimmed.

A similar question than yours has been asked in the Amazon DynamoDB forum as well (see Curious nature of the "Number" type) and the answer from Stefano@AWS sheds more light on the issue:

  • The "Number" type has 38 digits of precision These are actual decimal digits. So it can represent pretty large numbers, and there is no precision loss.
  • How much space does a Number value take up? Not too much. Our internal representation is variable length, so the size is correlated to the actual (vs. maximum) number of digits in the value. Leading and trailing zeroes are trimmed btw. [emphasis mine]

Christopher Smith's follow up post presents more insights into the resulting ramifications regarding storage consumption and its calculation, he concludes:

The existing API provides very little insight in to storage consumption, even though that is part (admittedly not that significant) of the billing. The only information is the aggregate table size, and even that data is potentially hours out of sync.

While Amazon does not expose it's billing data via an API yet, they they'll hopefully add an option to retrieve some information regarding item size to the DynamoDB API at some point, as suggested by Christopher.

like image 82
Steffen Opel Avatar answered Sep 22 '22 17:09

Steffen Opel