sldon
sldon

Reputation: 31

DAX doesn't get cache hits when used with DynamoDBMapper

I'm using DAX client along with DyanamoDBMapper. I'm using the following dependencies.

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-dynamodb</artifactId>
            <version>1.11.751</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>amazon-dax-client</artifactId>
            <version>1.0.205917.0</version>
        </dependency>

And the following code shows how the Mapper is initialized

    AmazonDaxClientBuilder builder = AmazonDaxClientBuilder.standard();
    builder.withRegion("<region>");
    builder.withEndpointConfiguration("<DAX ednpoint>");
    client = builder.build();
    DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(client);

When using this setup, in DAX metrics I see 0 cache hits and 0 cache misses for queries. But when I remove the mapper and using the table to query I can see cache hits.

I'm not using consistent reads as described here. AWS DAX cluster has zero cache hits and cache miss

Am I doing something wrong here or missing any configuration step here?

Also would like to know whether there's any way to get DAX cache hit or miss details for each request so debugging could be a bit easier.

Upvotes: 1

Views: 646

Answers (1)

sldon
sldon

Reputation: 31

The reason for the cache misses was with the DynamoDBQueryExpression which sets consistentRead flag to true by default.

Although DynamoDBMapperConfig by default does EVENTUAL consistent reads, DynamoDBQueryExpression is set to consistent reads. Due to this if you are using DynamoDBQueryExpression you have to explicitly set consistentRead to false.

When consistent reads are requested DAX requests are forwarded directly to DynamoDB and that's why we didn't see cache hits at DAX metrics.

Upvotes: 2

Related Questions