-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standalone works, SaaS shield is failing to reach the local TSP for me
- Loading branch information
Showing
9 changed files
with
226 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
java/src/jmh/java/com/ironcorelabs/ironcore_alloy_java/SaasShieldBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package test; | ||
|
||
import com.ironcorelabs.ironcore_alloy_java.*; | ||
import org.openjdk.jmh.annotations.*; | ||
import java.util.*; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@State(Scope.Benchmark) | ||
@Fork(1) | ||
@Warmup(iterations = 1) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | ||
public class SaasShieldBenchmark { | ||
|
||
private PlaintextDocument smallPlaintext; | ||
private PlaintextDocument mediumPlaintext; | ||
private PlaintextDocument largePlaintext; | ||
private PlaintextDocument extraLargePlaintext; | ||
private EncryptedDocument smallEncrypted; | ||
private EncryptedDocument mediumEncrypted; | ||
private EncryptedDocument largeEncrypted; | ||
private EncryptedDocument extraLargeEncrypted; | ||
private PlaintextDocuments batchPlaintexts; | ||
|
||
private final float approximationFactor = 1.1f; | ||
private final String tspUri = System.getenv().getOrDefault("TSP_ADDRESS", "http://localhost"); | ||
private final String tspPort = System.getenv().getOrDefault("TSP_PORT", "32804"); | ||
private final TenantId tenantId = new TenantId(System.getenv().getOrDefault("TENANT_ID", "tenant-gcp-l")); | ||
private final String apiKey = System.getenv().getOrDefault("API_KEY", "0WUaXesNgbTAuLwn"); | ||
|
||
private SaasShieldConfiguration saasShieldConfig; | ||
private SaasShield saasShieldSdk; | ||
private final AlloyMetadata metadata = AlloyMetadata.newSimple(tenantId); | ||
|
||
@Setup | ||
public void setUp() throws Exception { | ||
saasShieldConfig = new SaasShieldConfiguration(tspUri + ":" + tspPort, apiKey, true, approximationFactor); | ||
saasShieldSdk = new SaasShield(saasShieldConfig); | ||
smallPlaintext = generatePlaintextDocument(1, 1); | ||
mediumPlaintext = generatePlaintextDocument(100, 1); | ||
largePlaintext = generatePlaintextDocument(10_000, 1); | ||
extraLargePlaintext = generatePlaintextDocument(1_000_000, 1); | ||
|
||
batchPlaintexts = new PlaintextDocuments(new HashMap<>()); | ||
int numDocuments = 10; | ||
int numFields = 10; | ||
int fieldSize = 10; | ||
|
||
for (int i = 1; i <= numDocuments; i++) { | ||
batchPlaintexts.value().put(new DocumentId("doc" + i), generatePlaintextDocument(fieldSize, numFields)); | ||
} | ||
|
||
smallEncrypted = saasShieldSdk.standard().encrypt(smallPlaintext, metadata).get(); | ||
mediumEncrypted = saasShieldSdk.standard().encrypt(mediumPlaintext, metadata).get(); | ||
largeEncrypted = saasShieldSdk.standard().encrypt(largePlaintext, metadata).get(); | ||
extraLargeEncrypted = saasShieldSdk.standard().encrypt(extraLargePlaintext, metadata).get(); | ||
} | ||
|
||
@TearDown | ||
public void tearDown() { | ||
saasShieldSdk.close(); | ||
} | ||
|
||
private PlaintextDocument generatePlaintextDocument(int bytesPerField, int numFields) { | ||
PlaintextDocument documentMap = new PlaintextDocument(new HashMap<>()); | ||
for (int i = 1; i <= numFields; i++) { | ||
PlaintextBytes byteArray = new PlaintextBytes(new byte[bytesPerField]); | ||
new Random().nextBytes(byteArray.value()); | ||
documentMap.value().put(new FieldId("field" + i), byteArray); | ||
} | ||
return documentMap; | ||
} | ||
|
||
private void encrypt(PlaintextDocument plaintext) throws Exception { | ||
saasShieldSdk.standard().encrypt(plaintext, metadata).get(); | ||
} | ||
|
||
private void decrypt(EncryptedDocument document) throws Exception { | ||
saasShieldSdk.standard().decrypt(document, metadata).get(); | ||
} | ||
|
||
@Benchmark | ||
public void tspEncrypt1B() throws Exception { | ||
encrypt(smallPlaintext); | ||
} | ||
|
||
@Benchmark | ||
public void tspEncrypt100B() throws Exception { | ||
encrypt(mediumPlaintext); | ||
} | ||
|
||
@Benchmark | ||
public void tspEncrypt10KB() throws Exception { | ||
encrypt(largePlaintext); | ||
} | ||
|
||
@Benchmark | ||
public void tspEncrypt1MB() throws Exception { | ||
encrypt(extraLargePlaintext); | ||
} | ||
|
||
@Benchmark | ||
public void tspDecrypt1B() throws Exception { | ||
decrypt(smallEncrypted); | ||
} | ||
|
||
@Benchmark | ||
public void tspDecrypt100B() throws Exception { | ||
decrypt(mediumEncrypted); | ||
} | ||
|
||
@Benchmark | ||
public void tspDecrypt10KB() throws Exception { | ||
decrypt(largeEncrypted); | ||
} | ||
|
||
@Benchmark | ||
public void tspDecrypt1MB() throws Exception { | ||
decrypt(extraLargeEncrypted); | ||
} | ||
|
||
@Benchmark | ||
public void batchEncrypt10DocsOf100B() throws Exception { | ||
saasShieldSdk.standard().encryptBatch(batchPlaintexts, metadata).get(); | ||
} | ||
} |
Oops, something went wrong.