Last active
July 7, 2017 19:26
-
-
Save abdennour/9628b500f18cf87349aa4ce8e893a3dd to your computer and use it in GitHub Desktop.
Calculate required read throughput for AWS DynamoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* [calculate description] | |
* @method calculate | |
* @param {Number} itemsCount number of items to be read | |
* @param {Number} itemsRequiredTimeRead required time in seconds to read those items | |
* @param {Number} itemSize the size of each item in KB | |
* @param {Boolean} isStrongRead the consistency model of Read : Strong or eventual | |
* @return {Number} Read throughput | |
*/ | |
function calculate({itemsCount, itemsRequiredTimeRead, itemSize}, isStrongRead = true) { | |
const READ_UNIT = 4 ;//kb | |
const itemsPerSecond = itemsCount/itemsRequiredTimeRead; | |
const itemReadUnits = Math.ceil(itemSize / READ_UNIT) | |
const readThroughput = itemReadUnits * itemsPerSecond; | |
return Math.ceil(isStrongRead ? readThroughput : (readThroughput/2)); | |
} | |
module.exports = calculate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const calculateReadThroughput = require('./calculate-dynamodb-read-throughput'); | |
/** | |
* -- Example 1-- | |
You have an application that requires to read 10 items of 6kB per second using eventual consistency. | |
What should you set the read throughput to ? | |
-- Analysis | |
itemsCount = 10 | |
itemsRequiredTimeRead = 1 second (per second) | |
itemSize = 6 (6kB) | |
isStrongRead = false (Eventual consistency) | |
-- Solution | |
*/ | |
calculateReadThroughput({itemsCount: 10, itemsRequiredTimeRead : 1, itemSize: 6}, false) | |
// RESULT : 10 units of read throughput | |
/***************************************** | |
* -- Example 2-- | |
You have a motion sensor which reads 1200 items of data every minute. | |
Each item consists of 5kb. Your application uses eventually consistent reads. | |
What should you set the read throughput to? | |
-- Analysis | |
itemsCount = 1200 | |
itemsRequiredTimeRead = 60 second (evey minute = evey 60 seconds) | |
itemSize = 5 (5kB) | |
isStrongRead = false (Eventual consistency) | |
-- Solution | |
*/ | |
calculateReadThroughput({itemsCount: 1200, itemsRequiredTimeRead : 60, itemSize: 5}, false) | |
// RESULT : 20 units of read throughput |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment