From ea06c88ea0cb74ce853f2d21c6798065285be600 Mon Sep 17 00:00:00 2001 From: samvaity Date: Mon, 3 Jan 2022 13:25:15 -0800 Subject: [PATCH] update to use config to switch use of shared client --- eng/versioning/version_client.txt | 2 +- sdk/core/azure-core-perf/pom.xml | 2 +- .../azure/core/perf/GetBlobProperties.java | 55 ++++++++++++++----- .../azure/core/perf/UploadFromFileTest.java | 52 ++++++++++++++---- .../com/azure/core/perf/core/ServiceTest.java | 11 +++- sdk/storage/azure-storage-blob/pom.xml | 2 +- 6 files changed, 92 insertions(+), 32 deletions(-) diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index f2e94174595de..2a57b09d70361 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -65,6 +65,7 @@ com.azure:azure-communication-networktraversal;1.0.0-beta.1;1.0.0-beta.2 com.azure:azure-containers-containerregistry;1.0.0-beta.5;1.0.0-beta.6 com.azure:azure-containers-containerregistry-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-core;1.23.1;1.24.0-beta.1 +com.azure:azure-core-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-core-amqp;2.3.5;2.4.0-beta.1 com.azure:azure-core-amqp-experimental;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-core-experimental;1.0.0-beta.21;1.0.0-beta.22 @@ -339,7 +340,6 @@ com.azure.tools:azure-sdk-archetype;1.0.0;1.0.0 # note: The unreleased dependencies will not be manipulated with the automatic PR creation code. # In the pom, the version update tag after the version should name the unreleased package and the dependency version: # - unreleased_com.azure:azure-core;1.24.0-beta.1 unreleased_com.azure:azure-core-http-netty;1.12.0-beta.1 diff --git a/sdk/core/azure-core-perf/pom.xml b/sdk/core/azure-core-perf/pom.xml index 64d8c0a5226be..19eaace16c886 100644 --- a/sdk/core/azure-core-perf/pom.xml +++ b/sdk/core/azure-core-perf/pom.xml @@ -32,7 +32,7 @@ com.azure azure-storage-blob - 12.13.0 + 12.13.0-beta.1 diff --git a/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/GetBlobProperties.java b/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/GetBlobProperties.java index d8210d76ef204..43037e41ce00e 100644 --- a/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/GetBlobProperties.java +++ b/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/GetBlobProperties.java @@ -3,17 +3,17 @@ package com.azure.core.perf; +import com.azure.core.http.HttpClient; +import com.azure.core.http.netty.NettyAsyncHttpClientProvider; import com.azure.core.perf.core.ServiceTest; +import com.azure.core.util.HttpClientOptions; import com.azure.perf.test.core.PerfStressOptions; import com.azure.storage.blob.BlobContainerAsyncClient; import com.azure.storage.blob.BlobContainerClient; import com.azure.storage.blob.BlobServiceAsyncClient; import com.azure.storage.blob.BlobServiceClient; -import com.azure.storage.blob.models.BlobProperties; import reactor.core.publisher.Mono; -import java.util.UUID; - public class GetBlobProperties extends ServiceTest { public GetBlobProperties(PerfStressOptions options) { super(options); @@ -31,25 +31,52 @@ public Mono globalCleanupAsync() { @Override public void run() { - String blobName = "perfblobtest-" + UUID.randomUUID(); - BlobServiceClient storageClient = blobServiceClientBuilder.buildClient(); + if (useSharedClient) { + BlobServiceClient blobServiceClient = blobServiceClientBuilder.buildClient(); + performGetProperties(blobServiceClient); + } else { + // use a customized http client + HttpClientOptions clientOptions = new HttpClientOptions().setMaximumConnectionPoolSize(50); + HttpClient client1 = new NettyAsyncHttpClientProvider().createInstance(clientOptions); + + BlobServiceClient blobServiceClient = blobServiceClientBuilder + .httpClient(client1) + .buildClient(); - BlobContainerClient blobContainerClient = storageClient.createBlobContainer("perfupload" + UUID.randomUUID()); - BlobProperties blobProperties = blobContainerClient.getBlobClient(blobName).getProperties(); - assert blobProperties.getCreationTime() != null; - assert blobProperties.getExpiresOn() != null; + performGetProperties(blobServiceClient); + } } @Override public Mono runAsync() { - String blobName = "perfblobtest-" + UUID.randomUUID(); - BlobServiceAsyncClient storageAsyncClient = blobServiceClientBuilder.buildAsyncClient(); + if (useSharedClient) { + BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder.buildAsyncClient(); + return performGetPropertiesAsync(blobServiceAsyncClient); + } else { + // use a customized http client + HttpClientOptions clientOptions = new HttpClientOptions().setMaximumConnectionPoolSize(50); + HttpClient client1 = new NettyAsyncHttpClientProvider().createInstance(clientOptions); + + BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder + .httpClient(client1) + .buildAsyncClient(); + + return performGetPropertiesAsync(blobServiceAsyncClient); + } + } + + private void performGetProperties(BlobServiceClient blobServiceClient) { + BlobContainerClient blobContainerClient = blobServiceClient.createBlobContainer(CONTAINER_NAME); + blobContainerClient.getBlobClient(BLOB_NAME).getProperties(); + } + + private Mono performGetPropertiesAsync(BlobServiceAsyncClient blobServiceAsyncClient) { + BlobContainerAsyncClient blobContainerAsyncClient + = blobServiceAsyncClient.createBlobContainer(CONTAINER_NAME).block(); - BlobContainerAsyncClient - blobContainerAsyncClient = storageAsyncClient.createBlobContainer("perfupload" + UUID.randomUUID()).block(); - return blobContainerAsyncClient.getBlobAsyncClient(blobName) + return blobContainerAsyncClient.getBlobAsyncClient(BLOB_NAME) .getProperties() .then(); } diff --git a/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/UploadFromFileTest.java b/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/UploadFromFileTest.java index 13c2ca5254233..87b677f8d902d 100644 --- a/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/UploadFromFileTest.java +++ b/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/UploadFromFileTest.java @@ -3,7 +3,10 @@ package com.azure.core.perf; +import com.azure.core.http.HttpClient; +import com.azure.core.http.netty.NettyAsyncHttpClientProvider; import com.azure.core.perf.core.ServiceTest; +import com.azure.core.util.HttpClientOptions; import com.azure.perf.test.core.PerfStressOptions; import com.azure.storage.blob.BlobClient; import com.azure.storage.blob.BlobContainerClient; @@ -11,8 +14,6 @@ import com.azure.storage.blob.BlobServiceClient; import reactor.core.publisher.Mono; -import java.util.UUID; - public class UploadFromFileTest extends ServiceTest { public UploadFromFileTest(PerfStressOptions options) { super(options); @@ -30,25 +31,52 @@ public Mono globalCleanupAsync() { @Override public void run() { - String blobName = "perfblobtest-" + UUID.randomUUID(); - BlobServiceClient storageClient = blobServiceClientBuilder.buildClient(); + if (useSharedClient) { + BlobServiceClient blobServiceClient = blobServiceClientBuilder.buildClient(); + performUploadFromFile(blobServiceClient); - BlobContainerClient blobContainerClient = storageClient.createBlobContainer("perfupload" + UUID.randomUUID()); - BlobClient blobClient = blobContainerClient.getBlobClient(blobName); - blobClient.uploadFromFile(filePath, true); + } else { + // use a customized http client + HttpClientOptions clientOptions = new HttpClientOptions().setMaximumConnectionPoolSize(50); + HttpClient client1 = new NettyAsyncHttpClientProvider().createInstance(clientOptions); + + BlobServiceClient blobServiceClient = blobServiceClientBuilder + .httpClient(client1) + .buildClient(); + performUploadFromFile(blobServiceClient); + } } @Override public Mono runAsync() { - String blobName = "perfblobtest-" + UUID.randomUUID(); - BlobServiceAsyncClient storageAsyncClient = blobServiceClientBuilder.buildAsyncClient(); + if (useSharedClient) { + BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder.buildAsyncClient(); + return performUploadFromFileAsync(blobServiceAsyncClient); + } else { + // use a customized http client + HttpClientOptions clientOptions = new HttpClientOptions().setMaximumConnectionPoolSize(50); + HttpClient client1 = new NettyAsyncHttpClientProvider().createInstance(clientOptions); - return storageAsyncClient.createBlobContainer("perfupload" + UUID.randomUUID()) - .flatMap(blobContainerAsyncClient -> blobContainerAsyncClient.getBlobAsyncClient(blobName) - .uploadFromFile(filePath, true)); + BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder + .httpClient(client1) + .buildAsyncClient(); + + return performUploadFromFileAsync(blobServiceAsyncClient); + } + } + private void performUploadFromFile(BlobServiceClient blobServiceClient) { + BlobContainerClient blobContainerClient = blobServiceClient.createBlobContainer(CONTAINER_NAME); + BlobClient blobClient = blobContainerClient.getBlobClient(BLOB_NAME); + blobClient.uploadFromFile(filePath, true); + } + + private Mono performUploadFromFileAsync(BlobServiceAsyncClient blobServiceAsyncClient) { + return blobServiceAsyncClient.createBlobContainer(CONTAINER_NAME) + .flatMap(blobContainerAsyncClient -> blobContainerAsyncClient.getBlobAsyncClient(BLOB_NAME) + .uploadFromFile(filePath, true)); } } diff --git a/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/core/ServiceTest.java b/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/core/ServiceTest.java index 9aa21aeeeac93..0fdf4da13bc56 100644 --- a/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/core/ServiceTest.java +++ b/sdk/core/azure-core-perf/src/main/java/com/azure/core/perf/core/ServiceTest.java @@ -9,10 +9,16 @@ import com.azure.perf.test.core.PerfStressTest; import com.azure.storage.blob.BlobServiceClientBuilder; +import java.util.UUID; + public abstract class ServiceTest extends PerfStressTest { - protected final BlobServiceClientBuilder blobServiceClientBuilder; + protected BlobServiceClientBuilder blobServiceClientBuilder; protected final String filePath; + protected final boolean useSharedClient; + protected static final String CONTAINER_NAME = "perfstress-" + UUID.randomUUID(); + protected static final String BLOB_NAME = "perfblobtest-" + UUID.randomUUID(); + private final Configuration configuration; public ServiceTest(TOptions options) { @@ -20,7 +26,7 @@ public ServiceTest(TOptions options) { configuration = Configuration.getGlobalConfiguration().clone(); String connectionString = configuration.get("STORAGE_CONNECTION_STRING"); filePath = configuration.get("FILE_PATH"); - + useSharedClient = CoreUtils.isNullOrEmpty(configuration.get("USE_SHARED_CLIENT")); if (CoreUtils.isNullOrEmpty(connectionString)) { throw new IllegalStateException("Environment variable STORAGE_CONNECTION_STRING must be set"); @@ -30,7 +36,6 @@ public ServiceTest(TOptions options) { throw new IllegalStateException("Environment variable 'FILE_PATH' must be set"); } - // Set up the service client builder blobServiceClientBuilder = new BlobServiceClientBuilder().connectionString(connectionString); } diff --git a/sdk/storage/azure-storage-blob/pom.xml b/sdk/storage/azure-storage-blob/pom.xml index f3361b0fdaae4..93431cfe31287 100644 --- a/sdk/storage/azure-storage-blob/pom.xml +++ b/sdk/storage/azure-storage-blob/pom.xml @@ -83,7 +83,7 @@ com.azure azure-core-http-netty - 1.11.4 + 1.12.0-beta.1 com.azure