2
votes

In my table "products_1", I've configured 1 capacity unit Read and 1 capacity unit Write.

I'm using AWS PHP SDK to write 8 items into DynamoDB using "BatchWriteItem". The code returned this response:

Object
(
    [structure:protected] => 
    [data:protected] => Array
        (
            [ConsumedCapacity] => Array
                (
                    [0] => Array
                        (
                            [CapacityUnits] => 8
                            [TableName] => products_1
                        )

                )

            [UnprocessedItems] => Array
                (
                )

        )

)

As you can see, it has used 8 capacity units, which is correct.

But when I checked the Monitor in AWS Console, I couldn't see any entry in "Throttled Write Requests" charts. I was expecting the write requests would be throttled, since I assume "BatchWriteItem" would write 8 items within a second.

Is my assumption wrong? If not, I'm wondering why the writes don't show up in "Throttled Write Requests" chart.

3

3 Answers

3
votes

The console shows averages over a time period of 5 minutes. Calculate sum of used units: 8 units / 300 secs = 0.027 units per second. Looks like you were not throttled.

Quoting AWS on how to work out provisioned throughput:

Use the Sum value to calculate the provisioned throughput. For example, get the Sum value over a span of 5 minutes. Divide the Sum value by the number of seconds in 5 minutes (300) to get an average for the ConsumedWriteCapacityUnits per second. You can compare the calculated value to the provisioned throughput value you provide Amazon DynamoDB.

2
votes

Amazon DynamoDB basically allows for bursts of activity without getting throttled, but if you were to maintain operations/second above your provisioned amount for a period of time, you would start getting throttled.

For non-batch operations, the AWS SDK for PHP also retries throttled requests automatically using an exponential backoff algorithm, so even if you get throttled, you won't necessarily get an error in your PHP code.

In the case of the batch operations, like you are using here, you will know if you have been throttled, because you will have things show up in the UnprocessedItems part of the response.

Separate, but related: if you are planning up doing a lot of put operations and are concerned about throttling, you should check out the WriteRequestBatch class of the SDK, which uses batching and queuing to make sure that all of your items get put, eventually.

0
votes

From the documentation:

DynamoDB currently retains up to 5 minutes (300 seconds) of unused read and write capacity. During an occasional burst of read or write activity, these extra capacity units can be consumed quickly—even faster than the per-second provisioned throughput capacity that you've defined for your table

Because you have configured 1 WCU for your table, as a result you saved around 300 WCUs in 5 minutes. So your batch request which consumes 8 WCUs does not throttle.