ablog

不器用で落着きのない技術者のメモ

Amazon DynamoDB Accelerator (DAX) のサンプル Java アプリを動かしてみる

まずは動かしてみる

$ pwd
/home/ec2-user
$ mkdir trydax
$ cd trydax
$ sudo yum install -y java-devel
$ wget http://sdk-for-java.amazonwebservices.com/latest/aws-java-sdk.zip
$ unzip aws-java-sdk.zip
$ wget http://dax-sdk.s3-website-us-west-2.amazonaws.com/java/DaxJavaClient-latest.jar
$ wget http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/samples/TryDax.zip
$ unzip TryDax.zip
$ export SDKVERSION=1.11.641 #aws-java-sdk-1.11.641などaws-java-sdk.zipを解凍したディレクトリ名でバージョンが分かる
$ export DAX_HOME=/home/ec2-user/trydax
$ export CLASSPATH=.:$DAX_HOME/DaxJavaClient-latest.jar:$DAX_HOME/aws-java-sdk-$SDKVERSION/lib/aws-java-sdk-$SDKVERSION.jar:$DAX_HOME/aws-java-sdk-$SDKVERSION/third-party/lib/*
$ javac TryDax*.java
  • 実行手順
    • DynamoDBエンドポイントにアクセス
$ java TryDax
    • DAXエンドポイントにアクセス
$ java TryDax dax-r4l-3nodes.******.clustercfg.dax.apne1.cache.amazonaws.com:8111

ちょっといじってみる

  • TryDax/java/TryDax.java を以下の通り編集
/**
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * This file is licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License. A copy of
 * the License is located at
 *
 * http://aws.amazon.com/apache2.0/
 *
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
*/
import com.amazonaws.services.dynamodbv2.document.DynamoDB;

public class TryDax {

    public static void main(String[] args) throws Exception {

        TryDaxHelper helper = new TryDaxHelper();
        TryDaxTests tests = new TryDaxTests();

        DynamoDB ddbClient = helper.getDynamoDBClient();
        DynamoDB daxClient = null;
        if (args.length >= 1) {
            daxClient = helper.getDaxClient(args[0]);
        }

        String tableName = "TryDaxTable";

        System.out.println("Creating table...");
        helper.createTable(tableName, ddbClient);
        System.out.println("Populating table...");
        helper.writeData(tableName, ddbClient, 10, 10);

        DynamoDB testClient = null;
        if (daxClient != null) {
            testClient = daxClient;
        } else {
            testClient = ddbClient;
        }

        System.out.println("Running GetItem, Scan, and Query tests...");
        System.out.println("First iteration of each test will result in cache misses");
        System.out.println("Next iterations are cache hits\n");

        // GetItem
        //tests.getItemTest(tableName, testClient, 1, 10, 5);
        tests.getItemTest(tableName, testClient, 1, 10, 1000); //★実行回数を5->1000に変更

        // Query
        tests.queryTest(tableName, testClient, 5, 2, 9, 1000); //★実行回数を5->1000に変更

        // Scan
        tests.scanTest(tableName, testClient, 100); //★実行回数を5->100に変更

        //helper.deleteTable(tableName, ddbClient); //★テーブルを削除しない
    }

}
$ javac TryDax*.java
$ java TryDax