【问题标题】:Scan dynamoDB table with restricted read or throughput limit使用受限读取或吞吐量限制扫描 dynamoDB 表
【发布时间】:2013-06-15 00:03:44
【问题描述】:

是否有示例 java 代码对 dynamoDB 表执行扫描操作,其中扫描操作仅使用特定百分比的吞吐量限制? 提前致谢。

【问题讨论】:

  • 我知道 elastic map reduce 可以做到这一点。

标签: nosql amazon-dynamodb


【解决方案1】:

昨天我们在AWS Java Developer Blog 上发布了一篇关于如何操作Rate Limited Scans in Amazon DynamoDB 的博文。我不确定您使用的是哪种编程语言,但如果您使用的是 Java,那么这种使用 GoogleGuava RateLimiter 类的方法可能适合您。但格雷格之前的回复也是正确的。如果您使用的是 Amazon Elastic Map Reduce,则 DynamoDB 插件支持 configurable read and write throughput percent 以在扫描您的表时限制自己。 DynamoDB 的Amazon Redshift integration 也有这个设置。

这是博客文章中的一个 sn-p,它展示了如何使用 RateLimiter 和 AWS SDK for Java 执行分页扫描,该扫描将自身限制为每秒消耗 25 个读取容量单位:

// Initialize the rate limiter to allow 25 read capacity units / sec
RateLimiter rateLimiter = RateLimiter.create(25.0);

// Track how much throughput we consume on each page
int permitsToConsume = 1;

// Initialize the pagination token
Map<String, AttributeValue> exclusiveStartKey = null;

do {
    // Let the rate limiter wait until our desired throughput "recharges"
    rateLimiter.acquire(permitsToConsume);

    // Do the scan
    ScanRequest scan = new ScanRequest()
        .withTableName("ProductCatalog")
        .withLimit(100)
        .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
        .withExclusiveStartKey(exclusiveStartKey);
    ScanResult result = dynamodb.scan(scan);
    exclusiveStartKey = result.getLastEvaluatedKey();

    // Account for the rest of the throughput we consumed,
    // now that we know how much that scan request cost
    double consumedCapacity = result.getConsumedCapacity().getCapacityUnits();
    permitsToConsume = (int)(consumedCapacity - 1.0);
    if(permitsToConsume <= 0) {
        permitsToConsume = 1;
    }

    // Process results here
    processYourResults(result);

} while (exclusiveStartKey  != null);

【讨论】:

  • 感谢您发布此信息。这正是我正在寻找的。​​span>
  • 这一行为什么是-1.0? permitToConsume = (int)(consumedCapacity - 1.0);
猜你喜欢
  • 1970-01-01
  • 2016-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-02
相关资源
最近更新 更多