DynamoDB : Slow Read when queried for first time

2019-07-11 06:47发布

Following is my code :

error_log('before query'.date("H:i:s:ms"));
$response = $client->query(array(
                                 "TableName" => "user",
                                 "KeyConditions" => array(
                                 "userId" => array( "ComparisonOperator" => ComparisonOperator::EQ,
                                 "AttributeValueList" => array(
                                                               array(Type::NUMBER => 2)
                                                               ))),
                                ));
error_log('after query'.date("H:i:s:ms"));
print_r($response);

My tables Read capacity is 6 reads/sec

Output of Error logs

before query 16:05:29:0229

after query 16:05:32:0232

Question: Why it took 3 secs to read the user for first time? If I add one more query after my first query then it take less than 1 sec to respond.

Any light on the path would be helpful

-Thanks

1条回答
戒情不戒烟
2楼-- · 2019-07-11 07:29

This can happen if you are executing this query from different region than database's instance or from local.

If you haven't uploaded file with this query to the same region as your dynamoDb then it will take some time to build connection with your DB instance. Try to upload this script on the same region's server as your DB and then try again.

查看更多
登录 后发表回答