我正在使用Kinesis存储从安装在EC2服务器上的Jmeter发送的记录。问题是,当我启动7200个线程并在我的Kinesis流上使用1个共享时,一切都正常工作。如果我启动了9000个线程,我会收到这个错误
Rate exceeded for shard shardId-000000000001 in stream Jmeter under account 769870455028. (Service: AmazonKinesis; Status Code: 400; Error Code: ProvisionedThroughputExceededException; Request ID: 98f687d9-ffbe-11e4-a897-357ee8c24764)
所以我增加了分片的数量,将其设置为2和3,但它不起作用。所以我认为问题不在于分片号,而在于我的java代码,或者我不知道还有什么问题。这是我的代码:
public MyKinesisClient( String streamName, int partitionKey, String accessKey, String secretKey, String endpoint, String serviceName, String regionId ) {
this.streamName=streamName;
this.partitionKey=partitionKey;
AWSCredentials credentials = null;
credentials = new BasicAWSCredentials(accessKey, secretKey);
kinesisClient = new AmazonKinesisClient(credentials);
kinesisClient.setEndpoint(endpoint,serviceName,regionId);
}
/**
* Metodo utilizzato per l'invio di un json a Kinesis
* @param json: com.amazonaws.util.json.JSONObject da inviare a Kinesis
* @throws UnsupportedEncodingException
* @throws JSONException
*/
public void sendJson(JSONObject json) throws UnsupportedEncodingException, JSONException {
try{
PutRecordRequest putRecordRequest = new PutRecordRequest();
putRecordRequest.setStreamName(streamName);
putRecordRequest.setData(ByteBuffer.wrap(json.toString().getBytes("utf-8")));
//putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", createTime).getBytes()));
putRecordRequest.setPartitionKey(String.format("partitionKey-%d", partitionKey));
kinesisClient.putRecord(putRecordRequest);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
有使用更多分片的说明吗?提前谢谢
发布于 2015-05-21 15:07:53
我使用两个分区键进行了解析。来自Amazon的定义:
分区键用于将记录隔离并路由到流的不同分片。分区键由您的数据生产者在向Amazon Kinesis流添加数据时指定。例如,假设您有一个包含两个分片(分片1和分片2)的流。您可以配置您的数据生产者使用两个分区键(key A和key B),这样所有key A的记录都会被添加到分片1中,所有key B的记录都会被添加到分片2中。
很明显,我必须为每个分片使用一个分区键,但这一点很重要:
作为这种散列机制的结果,具有相同分区键的所有数据记录都映射到流中的相同分片。但是,如果分区键的数量超过了分片的数量,则某些分片必然包含具有不同分区键的记录。从设计的角度来看,为了确保充分利用所有分片,分片的数量(由CreateStreamRequest的setShardCount方法指定)应该比唯一分区键的数量少得多,流向单个分区键的数据量也应该比分片的容量小得多。
发布于 2017-02-21 07:30:15
@luca如果您使用了6个线程组和6个分片,则会收到速率超出异常。因为每个分片每秒有5个getRecord请求的限制。请参考Read Throttle
https://stackoverflow.com/questions/30375816
复制