Sensor Table Size Calculation
Table structure:
-
Timestamp: Records the time when the sensor reading is taken.
-
Data column: It varies widely based on the type of sensor and the parameters being used to measure the data.
For example, in case of Chunk Writes sensor, parameters are chunkwrites_10K, chunkwrites_2K. Checkpoint sensor parameters are cp_time, ckpt_logid, physused, logused, etc.
-
Primary Key: It stores primary key (a few sensors include primary key).
Data types and size:
- Timestamp: Type - BIGINT, Size - 8 bytes
-
Data: BSON documents up to 4 KB are stored in-row.
Type - BSON, Size - 4096 bytes + 4 bytes (4 KB) = 4100 bytes
It takes 4 bytes extra to store BSON data. JSON and BSON documents up to 4 KB are stored in-row. Documents that are greater than 4 KB in size, are stored in the sbspace that is associated with the table, or the default sbspace if the table does not have a designated sbspace. The maximum size of a JSON or BSON document is 32 KB.
-
Primary Key: Stores character strings of varying length (up to 255 bytes).
Type - VARCHAR, Size - 255 bytes
The maximum length of a VARCHAR column is the defined length (255) plus 1 byte to store the length of the actual value.
Calculate row size using SQL query:
- Query to get row size of Checkpoint sensor:
SELECT rowsize FROM systables WHERE tabname = 's_1_checkpoint'; 4108 bytes
- Query to get row size of Chunk Writes
sensor:
SELECT rowsize FROM systables WHERE tabname = 's_1_chunkwrites’; 4108 bytes
Estimating row size:
Following example explains row size calculation:
-
Row size calculation without primary key:
row size = timestamp 8 bytes + data (4096 bytes + 4 bytes) = 4108 bytes per row
Hence, Table size for 1 hr (60 min) = 4 * 4108 = 16432 bytes
-
Row size calculation with primary key:
Row size = timestamp 8 bytes + data (4096 bytes + 4 bytes) + primary key (255 bytes + 1 byte) = 4364 bytes per row
Table size for 1 hr (60 min) = 4 * 4364 = 17456 bytes (in case of primary key)