Last active
April 24, 2016 22:38
Star
You must be signed in to star a gist
How many capacity units does a dynamodb scan use
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
def scanSizeTest(client: AmazonDynamoDBClient, tableName: String) = { | |
val recordCount = 100 | |
var recordSize = 10 | |
populateTable(client, tableName, recordCount, recordSize) | |
print(s"For batchGet of $recordCount count of $recordSize byte records (${recordCount * recordSize} bytes), used ${batchGetTable(client, tableName, recordCount)} units\n") | |
print(s"For scan of $recordCount count of $recordSize byte records (${recordCount * recordSize} bytes), used ${scanTable(client, tableName)} units\n") | |
recordSize = 100 | |
populateTable(client, tableName, recordCount, recordSize) | |
print(s"For scan of $recordCount count of $recordSize byte records (${recordCount * recordSize} bytes), used ${scanTable(client, tableName)} units\n") | |
recordSize = 1000 | |
populateTable(client, tableName, recordCount, recordSize) | |
print(s"For scan of $recordCount count of $recordSize byte records (${recordCount * recordSize} bytes), used ${scanTable(client, tableName)} units\n") | |
} | |
def batchGetTable(client: AmazonDynamoDBClient, tableName: String, recordCount: Int) = { | |
// Eventually consistent reads; make sure everything is in place | |
Thread.sleep(10000) | |
val keys = (0 until recordCount).map { i => Map("k" -> new AttributeValue().withS(i.toString)).asJava }.asJavaCollection | |
val ka = new KeysAndAttributes().withKeys(keys) | |
val res = client.batchGetItem(new BatchGetItemRequest() | |
.withRequestItems(Map(tableName -> ka)) | |
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL)) | |
res.getConsumedCapacity | |
} | |
def scanTable(client: AmazonDynamoDBClient, tableName: String) = { | |
// Scans are eventually consistent; make sure everything is in place | |
Thread.sleep(10000) | |
val res = client.scan(new ScanRequest() | |
.withTableName(tableName) | |
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL)) | |
res.getConsumedCapacity.getCapacityUnits | |
} | |
def populateTable(client:AmazonDynamoDBClient, tableName: String, recordCount: Int, dataSize: Int) = { | |
val fakeData = new Array[Byte](dataSize) | |
for (i <- 0 until recordCount) { | |
val res = client.putItem(new PutItemRequest() | |
.withTableName(tableName) | |
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL) | |
.withItem(Map("k" -> new AttributeValue().withS(i.toString), | |
"v" -> new AttributeValue().withB(ByteBuffer.wrap(fakeData))))) | |
} | |
print("Finished populating\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment