2013-01-13 77 views

回答

4

昨天我們發表了一篇關於AWS Java Developer Blog如何做Rate Limited Scans in Amazon DynamoDB的博客文章。我不確定你使用的是哪種編程語言,但是如果你使用的是Java,這種使用GoogleGuava類的方法可能適用於你。但格雷格早些時候的回覆也是正確的。如果您使用的是Amazon Elastic Map Reduce,則DynamoDB插件支持configurable read and write throughput percent,以便在掃描您的表時自行限制。 DynamoDB的Amazon Redshift integration也有這個設置。

下面是從博客文章,顯示如何執行分頁掃描本身限制了消費每使用RateLimiter秒25個的讀取容量單位的一個片段和AWS SDK for Java

// 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); 
+0

感謝您發佈此信息。這正是我正在尋找的。 – CruncherBigData

+2

爲什麼在這一行-1.0? allowsToConsume =(int)(consumedCapacity - 1.0); – Mike