From 4fc4a51b150ea13aee1450acea8ffe8b41a27459 Mon Sep 17 00:00:00 2001 From: Andy Jewell Date: Mon, 10 Jul 2023 11:25:17 -0400 Subject: [PATCH 1/4] feat: show multi-threeading in example --- ...mpoundBeaconSearchableEncryptionExample.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java index 5640a44ea..6aedab959 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java @@ -232,6 +232,23 @@ public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, Strin .build()) .build(); + // Perform PutItem and Query + QueryItemWithCompoundBeacon(ddb, ddbTableName); + + // If instead you were working in a multi-threaded context + // it might look like this + Runnable myThread = () -> { + for(int i = 0; i < 20; ++i) + QueryItemWithCompoundBeacon(ddb, ddbTableName); + }; + // increase once we expect threads to work + for(int i = 0; i < 1; ++i) { + Thread run = new Thread(myThread); + } + } + + public static void QueryItemWithCompoundBeacon(DynamoDbClient ddb, String ddbTableName) { + // 11. Put an item with both attributes used in the compound beacon. final HashMap item = new HashMap<>(); item.put("work_id", AttributeValue.builder().s("9ce39272-8068-4efd-a211-cd162ad65d4c").build()); From ded2f6851a108b894f65e5fa7af14b3d9566c384 Mon Sep 17 00:00:00 2001 From: Andy Jewell Date: Mon, 10 Jul 2023 16:38:08 -0400 Subject: [PATCH 2/4] use thread pool --- .../CompoundBeaconSearchableEncryptionExample.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java index 6aedab959..5e13606df 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; @@ -71,6 +73,7 @@ This table must have a Global Secondary Index (GSI) configured named "last4UnitC public class CompoundBeaconSearchableEncryptionExample { static String GSI_NAME = "last4UnitCompound-index"; + static int MAX_CONCURRENT_QUERY_THREADS = 1; public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, String branchKeyId, String branchKeyWrappingKmsKeyArn, String branchKeyDdbTableName) { @@ -241,10 +244,11 @@ public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, Strin for(int i = 0; i < 20; ++i) QueryItemWithCompoundBeacon(ddb, ddbTableName); }; - // increase once we expect threads to work - for(int i = 0; i < 1; ++i) { - Thread run = new Thread(myThread); + ExecutorService pool = Executors.newFixedThreadPool(MAX_CONCURRENT_QUERY_THREADS); + for(int i = 0; i < (2*MAX_CONCURRENT_QUERY_THREADS); i++) { + pool.execute(myThread); } + pool.shutdown(); } public static void QueryItemWithCompoundBeacon(DynamoDbClient ddb, String ddbTableName) { From a183073383c394a61e8152d6fc77b345a92e08b4 Mon Sep 17 00:00:00 2001 From: Andy Jewell Date: Fri, 14 Jul 2023 08:35:39 -0400 Subject: [PATCH 3/4] enable --- .../CompoundBeaconSearchableEncryptionExample.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java index 5e13606df..8b0513bce 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; @@ -73,7 +74,7 @@ This table must have a Global Secondary Index (GSI) configured named "last4UnitC public class CompoundBeaconSearchableEncryptionExample { static String GSI_NAME = "last4UnitCompound-index"; - static int MAX_CONCURRENT_QUERY_THREADS = 1; + static int MAX_CONCURRENT_QUERY_THREADS = 10; public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, String branchKeyId, String branchKeyWrappingKmsKeyArn, String branchKeyDdbTableName) { @@ -241,14 +242,16 @@ public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, Strin // If instead you were working in a multi-threaded context // it might look like this Runnable myThread = () -> { - for(int i = 0; i < 20; ++i) + for(int i = 0; i < 20; ++i) { QueryItemWithCompoundBeacon(ddb, ddbTableName); + } }; ExecutorService pool = Executors.newFixedThreadPool(MAX_CONCURRENT_QUERY_THREADS); for(int i = 0; i < (2*MAX_CONCURRENT_QUERY_THREADS); i++) { pool.execute(myThread); } pool.shutdown(); + try {pool.awaitTermination(30, TimeUnit.SECONDS);} catch (Exception e) {} } public static void QueryItemWithCompoundBeacon(DynamoDbClient ddb, String ddbTableName) { From 96aaed0d6578bbac1271f14a3d7246cf049293e3 Mon Sep 17 00:00:00 2001 From: Andy Jewell Date: Tue, 18 Jul 2023 17:06:17 -0400 Subject: [PATCH 4/4] rename --- .../CompoundBeaconSearchableEncryptionExample.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java index 8b0513bce..704a9a880 100644 --- a/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java +++ b/Examples/runtimes/java/DynamoDbEncryption/src/main/java/software/amazon/cryptography/examples/searchableencryption/CompoundBeaconSearchableEncryptionExample.java @@ -237,13 +237,13 @@ public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, Strin .build(); // Perform PutItem and Query - QueryItemWithCompoundBeacon(ddb, ddbTableName); + PutAndQueryItemWithCompoundBeacon(ddb, ddbTableName); // If instead you were working in a multi-threaded context // it might look like this Runnable myThread = () -> { for(int i = 0; i < 20; ++i) { - QueryItemWithCompoundBeacon(ddb, ddbTableName); + PutAndQueryItemWithCompoundBeacon(ddb, ddbTableName); } }; ExecutorService pool = Executors.newFixedThreadPool(MAX_CONCURRENT_QUERY_THREADS); @@ -254,7 +254,7 @@ public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, Strin try {pool.awaitTermination(30, TimeUnit.SECONDS);} catch (Exception e) {} } - public static void QueryItemWithCompoundBeacon(DynamoDbClient ddb, String ddbTableName) { + public static void PutAndQueryItemWithCompoundBeacon(DynamoDbClient ddb, String ddbTableName) { // 11. Put an item with both attributes used in the compound beacon. final HashMap item = new HashMap<>();