Last active
September 13, 2021 21:30
-
-
Save nate-gehringer/061136a84362373314c9e5421b4f0501 to your computer and use it in GitHub Desktop.
Estimates DynamoDB RCU / WCU settings for the specified operation parameters
This file contains hidden or 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 estimateDynamoDBThroughputSettings = ({ | |
| atomicRead = false, | |
| averageItemSizeBytes, | |
| desiredExecutionDurationHours, | |
| itemCount | |
| }) => { | |
| const totalItemSizeMegabytes = (itemCount * averageItemSizeBytes) / 1024 /* kilobytes */ / 1024 /* megabytes */; | |
| const readUnitsPerItem = atomicRead | |
| ? Math.max(Math.ceil(averageItemSizeBytes / 4096) /* 1 RCU = up to 4 KB */, 1) / 2 /* eventually consistent reads use 0.5 RCU */ | |
| : (averageItemSizeBytes / 4096 /* 1 RCU = up to 4 KB */) / 2 /* eventually consistent reads use 0.5 RCU */ | |
| ; | |
| const writeUnitsPerItem = Math.max(Math.ceil(averageItemSizeBytes / 1024) /* 1 WCU = up to 1 KB */, 1) /* eventually consistent writes use 1 WCU */; | |
| const totalReadUnits = itemCount * readUnitsPerItem; | |
| const totalWriteUnits = itemCount * writeUnitsPerItem; | |
| const desiredExecutionDurationSeconds = desiredExecutionDurationHours * 60 /* minutes */ * 60 /* seconds */; | |
| const estimatedReadCapacityUnits = Math.max( Math.ceil(totalReadUnits / desiredExecutionDurationSeconds), 1 ); | |
| const estimatedWriteCapacityUnits = Math.max( Math.ceil(totalWriteUnits / desiredExecutionDurationSeconds), 1 ); | |
| console.log(` | |
| DynamoDB items to read / write … | |
| \tCount: ${itemCount.toLocaleString()} | |
| \tAverage size: ${averageItemSizeBytes.toLocaleString()} bytes | |
| \t\t– Total size: ${totalItemSizeMegabytes.toFixed(1)} MB | |
| \t\t– Read units / item: ${readUnitsPerItem.toLocaleString()} | |
| \t\t- Write units / item: ${writeUnitsPerItem.toLocaleString()} | |
| \t\t- Total read units: ${totalReadUnits.toLocaleString()} | |
| \t\t- Total write units: ${totalWriteUnits.toLocaleString()} | |
| … in … | |
| \t${desiredExecutionDurationHours.toLocaleString()} hours (${desiredExecutionDurationSeconds.toLocaleString()} seconds) | |
| … requires the following estimated throughput values … | |
| \tRCU: ${estimatedReadCapacityUnits.toLocaleString()} | |
| \tWCU: ${estimatedWriteCapacityUnits.toLocaleString()} | |
| ` | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment