Example usage for com.amazonaws.services.dynamodbv2.model ProvisionedThroughput getReadCapacityUnits

List of usage examples for com.amazonaws.services.dynamodbv2.model ProvisionedThroughput getReadCapacityUnits

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model ProvisionedThroughput getReadCapacityUnits.

Prototype


public Long getReadCapacityUnits() 

Source Link

Document

The maximum number of strongly consistent reads consumed per second before DynamoDB returns a ThrottlingException.

Usage

From source file:com.cfelde.aws.ddb.management.TableThroughput.java

License:Open Source License

public void updateCapacity() {
    synchronized (lock) {
        try {/*from w w  w .j  a  v  a 2  s  .  com*/
            if (lastTableChange.plusMinutes(3).isAfter(new DateTime()))
                return;

            long readCapacity = requestedReadCapacity.get();
            long writeCapacity = requestedWriteCapacity.get();

            if (readCapacity > maxReadLimit)
                readCapacity = maxReadLimit;
            if (readCapacity < minReadLimit)
                readCapacity = minReadLimit;

            if (writeCapacity > maxWriteLimit)
                writeCapacity = maxWriteLimit;
            if (writeCapacity < minWriteLimit)
                writeCapacity = minWriteLimit;

            ProvisionedThroughputDescription ptd = ddb.describeTable(new DescribeTableRequest(tableName))
                    .getTable().getProvisionedThroughput();

            downscaleCounter.set(ptd.getNumberOfDecreasesToday());

            final long currentReadCapacity = ptd.getReadCapacityUnits();
            final long currentWriteCapacity = ptd.getWriteCapacityUnits();

            // Make sure we don't try to scale up more than 100%
            if (readCapacity > currentReadCapacity * 2)
                readCapacity = currentReadCapacity * 2;

            if (writeCapacity > currentWriteCapacity * 2)
                writeCapacity = currentWriteCapacity * 2;

            if (!isDownscaleAllowed() && readCapacity < currentReadCapacity)
                readCapacity = currentReadCapacity;
            if (!isDownscaleAllowed() && writeCapacity < currentWriteCapacity)
                writeCapacity = currentWriteCapacity;

            // Check if no change
            if (readCapacity == currentReadCapacity && writeCapacity == currentWriteCapacity)
                return;

            /*
            if (readCapacity < currentReadCapacity || writeCapacity < currentWriteCapacity)
            downscaleAllowed.set(false);
            */

            ProvisionedThroughput throughput = new ProvisionedThroughput();
            throughput.withReadCapacityUnits(readCapacity);
            throughput.withWriteCapacityUnits(writeCapacity);

            UpdateTableRequest request = new UpdateTableRequest(tableName, throughput);

            LOG.info("Changing throughput on " + tableName + " to: reads: " + throughput.getReadCapacityUnits()
                    + ", writes: " + throughput.getWriteCapacityUnits());
            ddb.updateTable(request);

            lastTableChange = new DateTime();
        } catch (Throwable t) {
            LOG.error("Exception in updateCapacity: " + t.getMessage(), t);
            exceptionCounter.incrementAndGet();
        }
    }
}