From 0c25bf0f3831e19f3608e2f2e1114972a629e327 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 12:34:21 +0100 Subject: [PATCH 01/11] add benchmark to retrieve products --- .../benchmark/ClientBenchmark.java | 112 ++++++++++++++++++ .../src/jmh/resources/logback-test.xml | 2 +- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index b3095eda06a..c42c83ecb1e 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -2,10 +2,19 @@ package com.commercetools.benchmark; import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import com.commercetools.api.client.ApiInternalLoggerFactory; import com.commercetools.api.client.ProjectApiRoot; import com.commercetools.api.defaultconfig.ApiRootBuilder; import com.commercetools.api.defaultconfig.ServiceRegion; +import com.commercetools.api.models.common.LocalizedString; +import com.commercetools.api.models.product.Product; +import com.commercetools.api.models.product_type.AttributeTypeBuilder; +import com.commercetools.api.models.product_type.ProductType; +import com.commercetools.api.models.tax_category.TaxCategory; import com.commercetools.compat.CompatSphereClient; import com.commercetools.http.apachehttp.CtApacheHttpClient; import com.commercetools.http.asynchttp.CtAsyncHttpClient; @@ -14,6 +23,7 @@ import io.sphere.sdk.client.BlockingSphereClient; import io.sphere.sdk.client.SphereClient; import io.sphere.sdk.client.SphereClientFactory; +import io.sphere.sdk.products.queries.ProductProjectionQuery; import io.sphere.sdk.projects.queries.ProjectGet; import io.vrap.rmf.base.client.oauth2.ClientCredentials; @@ -32,24 +42,36 @@ public static class ClientState { private BlockingSphereClient compatClient; + private List productsList; + + private TaxCategory taxCategory; + + private ProductType productType; + @Setup(Level.Trial) public void init() { ahcApiRoot = ApiRootBuilder.of(new CtAsyncHttpClient()) .defaultClient( ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(), ServiceRegion.GCP_EUROPE_WEST1) + .withInternalLoggerFactory(ApiInternalLoggerFactory::get, org.slf4j.event.Level.DEBUG, + org.slf4j.event.Level.DEBUG) .build(getProjectKey()); apacheApiRoot = ApiRootBuilder.of(new CtApacheHttpClient()) .defaultClient( ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(), ServiceRegion.GCP_EUROPE_WEST1) + .withInternalLoggerFactory(ApiInternalLoggerFactory::get, org.slf4j.event.Level.DEBUG, + org.slf4j.event.Level.DEBUG) .build(getProjectKey()); okhttpApiRoot = ApiRootBuilder.of(new CtOkHttp4Client()) .defaultClient( ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(), ServiceRegion.GCP_EUROPE_WEST1) + .withInternalLoggerFactory(ApiInternalLoggerFactory::get, org.slf4j.event.Level.DEBUG, + org.slf4j.event.Level.DEBUG) .build(getProjectKey()); final SphereClientFactory factory = SphereClientFactory.of(); @@ -60,16 +82,96 @@ public void init() { sphereClient = BlockingSphereClient.of(client, Duration.ofSeconds(10)); compatClient = BlockingSphereClient.of(CompatSphereClient.of(ahcApiRoot), Duration.ofSeconds(10)); + + productType = createProductType(); + + taxCategory = createTaxCategory(); + productsList = createProducts(taxCategory, productType); } @TearDown(Level.Trial) public void tearDown() { + deleteProducts(productsList); + deleteProductType(productType); + deleteTaxCategory(taxCategory); ahcApiRoot.close(); compatClient.close(); apacheApiRoot.close(); okhttpApiRoot.close(); sphereClient.close(); } + + public ProductType createProductType() { + String suffix = randomKey(); + return ahcApiRoot.productTypes() + .create(builder -> builder.key("benchmark-" + suffix) + .name("benchmark") + .description("benchmark") + .plusAttributes(attributeBuilder -> attributeBuilder.type(AttributeTypeBuilder::textBuilder) + .isRequired(false) + .name("benchmark-color") + .isSearchable(true) + .label(LocalizedString.ofEnglish("color")))) + .executeBlocking() + .getBody(); + } + + private TaxCategory createTaxCategory() { + String suffix = randomKey(); + return ahcApiRoot.taxCategories() + .create(builder -> builder.key("benchmark-" + suffix) + .name("benchmark-" + suffix) + .description("benchmark-" + suffix) + .plusRates(rateBuilder -> rateBuilder.name("Mwst") + .country("DE") + .amount(0.19) + .includedInPrice(true))) + .executeBlocking() + .getBody(); + } + + private List createProducts(TaxCategory taxCategory, ProductType productType) { + String productSuffix = randomKey(); + List products = new ArrayList<>(); + for (int i = 0; i < 150; i++) { + String suffix = productSuffix + "-" + i; + Product product = ahcApiRoot.products() + .create( + builder -> builder.key("benchmark-" + suffix) + .productType(p -> p.id(productType.getId())) + .taxCategory(t -> t.id(taxCategory.getId())) + .name(LocalizedString.ofEnglish("benchmark-" + suffix)) + .slug(LocalizedString.ofEnglish("benchmark-" + suffix)) + .description(LocalizedString.ofEnglish("benchmark-" + suffix)) + .masterVariant(variantBuilder -> variantBuilder.key("benchmark-variant1-" + suffix) + .sku("benchmark-variant1-" + suffix) + .plusPrices(price -> price.country("DE") + .value(moneyBuilder -> moneyBuilder.centAmount(100L) + .currencyCode("EUR"))) + .plusAttributes( + attribute -> attribute.name("benchmark-color").value("red" + suffix)))) + .executeBlocking() + .getBody(); + products.add(product); + } + return products; + } + + private void deleteProducts(List products) { + products.forEach(product -> ahcApiRoot.products().delete(product).executeBlocking()); + } + + private void deleteProductType(ProductType productType) { + ahcApiRoot.productTypes().delete(productType).executeBlocking(); + } + + private void deleteTaxCategory(TaxCategory taxCategory) { + ahcApiRoot.taxCategories().delete(taxCategory).executeBlocking(); + } + + public static String randomKey() { + return "random-key-" + UUID.randomUUID().toString(); + } } @Benchmark @@ -97,6 +199,16 @@ public void retrieveProjectV2_Compat(ClientState state) { state.compatClient.executeBlocking(ProjectGet.of()); } + @Benchmark + public void retrieveProductsV2_Compat(ClientState state) { + state.compatClient.executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + } + + @Benchmark + public void retrieveProductsV1_AHC(ClientState state) { + state.sphereClient.executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + } + public static String getProjectKey() { return System.getenv("CTP_PROJECT_KEY"); } diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/resources/logback-test.xml b/commercetools/commercetools-sdk-compat-v1/src/jmh/resources/logback-test.xml index 4fcc733a225..9a448740e59 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/resources/logback-test.xml +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/resources/logback-test.xml @@ -11,7 +11,7 @@ - + From 506f751cd40e1ba5bed889af309559ead9f560af Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 13:17:05 +0100 Subject: [PATCH 02/11] exclude projects retrieval benchmarks --- .../commercetools-sdk-compat-v1/build.gradle | 1 + .../benchmark/ClientBenchmark.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/commercetools/commercetools-sdk-compat-v1/build.gradle b/commercetools/commercetools-sdk-compat-v1/build.gradle index 50e981956e9..9fe05b5d38b 100644 --- a/commercetools/commercetools-sdk-compat-v1/build.gradle +++ b/commercetools/commercetools-sdk-compat-v1/build.gradle @@ -6,6 +6,7 @@ jmh { threads = 25 fork = 3 timeOnIteration = '1s' + excludes = ['^retrieveProject.*'] } dependencies { diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index c42c83ecb1e..95a6948c462 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -42,6 +42,8 @@ public static class ClientState { private BlockingSphereClient compatClient; + private BlockingSphereClient compatOkHttpClient; + private List productsList; private TaxCategory taxCategory; @@ -83,6 +85,8 @@ public void init() { compatClient = BlockingSphereClient.of(CompatSphereClient.of(ahcApiRoot), Duration.ofSeconds(10)); + compatOkHttpClient = BlockingSphereClient.of(CompatSphereClient.of(okhttpApiRoot), Duration.ofSeconds(10)); + productType = createProductType(); taxCategory = createTaxCategory(); @@ -199,16 +203,30 @@ public void retrieveProjectV2_Compat(ClientState state) { state.compatClient.executeBlocking(ProjectGet.of()); } + @Benchmark + public void retrieveProjectV2_CompatOkHttp(ClientState state) { + state.compatOkHttpClient.executeBlocking(ProjectGet.of()); + } + @Benchmark public void retrieveProductsV2_Compat(ClientState state) { state.compatClient.executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); } + public void retrieveProductsV2_CompatOkHttp(ClientState state) { + state.compatOkHttpClient.executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + } + @Benchmark public void retrieveProductsV1_AHC(ClientState state) { state.sphereClient.executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); } + @Benchmark + public void retrieveProductsV2_OkHtp(ClientState state) { + state.okhttpApiRoot.productProjections().get().withLimit(100).executeBlocking(); + } + public static String getProjectKey() { return System.getenv("CTP_PROJECT_KEY"); } From ba066ec73d6bedbf9715308c4f3a09b69db21ab2 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 14:00:19 +0100 Subject: [PATCH 03/11] output results reduce number of forks --- .github/workflows/benchmark.yml | 2 ++ commercetools/commercetools-sdk-compat-v1/build.gradle | 2 +- .../jmh/java/com/commercetools/benchmark/ClientBenchmark.java | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 98b9a634362..f626e197067 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -26,3 +26,5 @@ jobs: CTP_CLIENT_SECRET: ${{ secrets.CTP_CLIENT_SECRET_PR }} CTP_PROJECT_KEY: ${{ secrets.CTP_PROJECT_KEY_PR }} CTP_JVM_SDK_LOG_LEVEL: OFF + - name: Output results + run: cat commercetools/commercetools-sdk-compat-v1/build/results/jmh/results.txt diff --git a/commercetools/commercetools-sdk-compat-v1/build.gradle b/commercetools/commercetools-sdk-compat-v1/build.gradle index 9fe05b5d38b..6845ca0e490 100644 --- a/commercetools/commercetools-sdk-compat-v1/build.gradle +++ b/commercetools/commercetools-sdk-compat-v1/build.gradle @@ -4,7 +4,7 @@ jmh { iterations = 10 benchmarkMode = ['thrpt', 'avgt'] threads = 25 - fork = 3 + fork = 1 timeOnIteration = '1s' excludes = ['^retrieveProject.*'] } diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index 95a6948c462..083889c498f 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -100,6 +100,7 @@ public void tearDown() { deleteTaxCategory(taxCategory); ahcApiRoot.close(); compatClient.close(); + compatOkHttpClient.close(); apacheApiRoot.close(); okhttpApiRoot.close(); sphereClient.close(); From 61a4fc72ae5b361826d7bd62d297e0283d684764 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 15:01:38 +0100 Subject: [PATCH 04/11] reduce threads --- commercetools/commercetools-sdk-compat-v1/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commercetools/commercetools-sdk-compat-v1/build.gradle b/commercetools/commercetools-sdk-compat-v1/build.gradle index 6845ca0e490..3d00671f3ff 100644 --- a/commercetools/commercetools-sdk-compat-v1/build.gradle +++ b/commercetools/commercetools-sdk-compat-v1/build.gradle @@ -3,10 +3,10 @@ apply plugin: "me.champeau.jmh" jmh { iterations = 10 benchmarkMode = ['thrpt', 'avgt'] - threads = 25 + threads = 10 fork = 1 timeOnIteration = '1s' - excludes = ['^retrieveProject.*'] + excludes = ['.*retrieveProject.*'] } dependencies { From 382e5b59c71ba19ad57180bdf2067a61f88bedc5 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 20:10:58 +0100 Subject: [PATCH 05/11] add more product benchmarks --- .../benchmark/ClientBenchmark.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index 083889c498f..222a15e228f 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -12,6 +12,7 @@ import com.commercetools.api.defaultconfig.ServiceRegion; import com.commercetools.api.models.common.LocalizedString; import com.commercetools.api.models.product.Product; +import com.commercetools.api.models.product.ProductProjectionPagedQueryResponse; import com.commercetools.api.models.product_type.AttributeTypeBuilder; import com.commercetools.api.models.product_type.ProductType; import com.commercetools.api.models.tax_category.TaxCategory; @@ -23,10 +24,14 @@ import io.sphere.sdk.client.BlockingSphereClient; import io.sphere.sdk.client.SphereClient; import io.sphere.sdk.client.SphereClientFactory; +import io.sphere.sdk.products.ProductProjection; import io.sphere.sdk.products.queries.ProductProjectionQuery; import io.sphere.sdk.projects.queries.ProjectGet; +import io.sphere.sdk.queries.PagedQueryResult; +import io.vrap.rmf.base.client.ApiHttpResponse; import io.vrap.rmf.base.client.oauth2.ClientCredentials; +import org.assertj.core.api.Assertions; import org.openjdk.jmh.annotations.*; public class ClientBenchmark { @@ -210,22 +215,45 @@ public void retrieveProjectV2_CompatOkHttp(ClientState state) { } @Benchmark - public void retrieveProductsV2_Compat(ClientState state) { - state.compatClient.executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + public void retrieveProductsV2_CompatAHC(ClientState state) { + final PagedQueryResult response = state.compatClient + .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + Assertions.assertThat(response.getCount()).isEqualTo(100); } + @Benchmark public void retrieveProductsV2_CompatOkHttp(ClientState state) { - state.compatOkHttpClient.executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + final PagedQueryResult response = state.compatOkHttpClient + .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + Assertions.assertThat(response.getCount()).isEqualTo(100); } @Benchmark public void retrieveProductsV1_AHC(ClientState state) { - state.sphereClient.executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + final PagedQueryResult response = state.sphereClient + .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + Assertions.assertThat(response.getCount()).isEqualTo(100); + + } + + @Benchmark + public void retrieveProductsV2_AHC(ClientState state) { + final ApiHttpResponse response = state.ahcApiRoot.productProjections() + .get() + .withLimit(100) + .executeBlocking(); + Assertions.assertThat(response.getBody().getCount()).isEqualTo(100); + } @Benchmark public void retrieveProductsV2_OkHtp(ClientState state) { - state.okhttpApiRoot.productProjections().get().withLimit(100).executeBlocking(); + final ApiHttpResponse response = state.okhttpApiRoot.productProjections() + .get() + .withLimit(100) + .executeBlocking(); + + Assertions.assertThat(response.getBody().getCount()).isEqualTo(100); } public static String getProjectKey() { From f84204e5330f43d88cec94a8b1f096472b91dd4b Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 20:37:12 +0100 Subject: [PATCH 06/11] fix v2 tests --- .../jmh/java/com/commercetools/benchmark/ClientBenchmark.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index 222a15e228f..43e3f948a06 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -233,13 +233,13 @@ public void retrieveProductsV1_AHC(ClientState state) { final PagedQueryResult response = state.sphereClient .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); Assertions.assertThat(response.getCount()).isEqualTo(100); - } @Benchmark public void retrieveProductsV2_AHC(ClientState state) { final ApiHttpResponse response = state.ahcApiRoot.productProjections() .get() + .withStaged(true) .withLimit(100) .executeBlocking(); Assertions.assertThat(response.getBody().getCount()).isEqualTo(100); @@ -250,6 +250,7 @@ public void retrieveProductsV2_AHC(ClientState state) { public void retrieveProductsV2_OkHtp(ClientState state) { final ApiHttpResponse response = state.okhttpApiRoot.productProjections() .get() + .withStaged(true) .withLimit(100) .executeBlocking(); From 45e9daa33908e90b9f7b2785bd5fb6de463aba21 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 21:31:56 +0100 Subject: [PATCH 07/11] enable project retrieval benchmark --- commercetools/commercetools-sdk-compat-v1/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commercetools/commercetools-sdk-compat-v1/build.gradle b/commercetools/commercetools-sdk-compat-v1/build.gradle index 3d00671f3ff..1ad0b2ec72b 100644 --- a/commercetools/commercetools-sdk-compat-v1/build.gradle +++ b/commercetools/commercetools-sdk-compat-v1/build.gradle @@ -4,9 +4,9 @@ jmh { iterations = 10 benchmarkMode = ['thrpt', 'avgt'] threads = 10 - fork = 1 + fork = 3 timeOnIteration = '1s' - excludes = ['.*retrieveProject.*'] +// excludes = ['.*retrieveProject.*'] } dependencies { From 20d7585e27d44735cb77889e5a7f8e888f4ad0f5 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 21:52:38 +0100 Subject: [PATCH 08/11] ensure AHC is used for v1 SDK --- commercetools/commercetools-sdk-compat-v1/build.gradle | 7 ++++--- .../java/com/commercetools/benchmark/ClientBenchmark.java | 3 ++- gradle-scripts/extensions.gradle | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/commercetools/commercetools-sdk-compat-v1/build.gradle b/commercetools/commercetools-sdk-compat-v1/build.gradle index 1ad0b2ec72b..28d04e2e894 100644 --- a/commercetools/commercetools-sdk-compat-v1/build.gradle +++ b/commercetools/commercetools-sdk-compat-v1/build.gradle @@ -4,9 +4,9 @@ jmh { iterations = 10 benchmarkMode = ['thrpt', 'avgt'] threads = 10 - fork = 3 - timeOnIteration = '1s' -// excludes = ['.*retrieveProject.*'] + fork = 1 + timeOnIteration = '3s' + excludes = ['.*retrieveProject.*'] } dependencies { @@ -24,6 +24,7 @@ dependencies { jmhImplementation project(':commercetools:commercetools-async-http-client') jmhImplementation project(':commercetools:commercetools-apachehttp-client') + jmhImplementation ctsdkv1.http version ctsdkv1.version testImplementation project(':commercetools:commercetools-http-client') testImplementation ctsdkv1.client version ctsdkv1.version testImplementation ctsdkv1.models version ctsdkv1.version diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index 43e3f948a06..865d9e75cf3 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -22,6 +22,7 @@ import com.commercetools.http.okhttp4.CtOkHttp4Client; import io.sphere.sdk.client.BlockingSphereClient; +import io.sphere.sdk.client.SphereAsyncHttpClientFactory; import io.sphere.sdk.client.SphereClient; import io.sphere.sdk.client.SphereClientFactory; import io.sphere.sdk.products.ProductProjection; @@ -81,7 +82,7 @@ public void init() { org.slf4j.event.Level.DEBUG) .build(getProjectKey()); - final SphereClientFactory factory = SphereClientFactory.of(); + final SphereClientFactory factory = SphereClientFactory.of(SphereAsyncHttpClientFactory::create); final SphereClient client = factory.createClient(getProjectKey(), //replace with your project key getClientId(), //replace with your client id getClientSecret()); //replace with your client secret diff --git a/gradle-scripts/extensions.gradle b/gradle-scripts/extensions.gradle index 8e0ef5c905c..d385bfb6ba1 100644 --- a/gradle-scripts/extensions.gradle +++ b/gradle-scripts/extensions.gradle @@ -7,6 +7,7 @@ ext { client: 'com.commercetools.sdk.jvm.core:commercetools-java-client-core:2.9.0', models: 'com.commercetools.sdk.jvm.core:commercetools-models:2.9.0', convenience: 'com.commercetools.sdk.jvm.core:commercetools-convenience:2.9.0', + http: 'com.commercetools.sdk.jvm.core:commercetools-java-client-ahc-2_12:2.9.0', version: { strictly '[1.62.0,)' prefer '2.9.0' From ac176d7325cb13c9b283d8af8bd7e6c3fe05b284 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 21:58:25 +0100 Subject: [PATCH 09/11] add apache client to benchmarks --- .../benchmark/ClientBenchmark.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index 865d9e75cf3..094225c99be 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -21,10 +21,7 @@ import com.commercetools.http.asynchttp.CtAsyncHttpClient; import com.commercetools.http.okhttp4.CtOkHttp4Client; -import io.sphere.sdk.client.BlockingSphereClient; -import io.sphere.sdk.client.SphereAsyncHttpClientFactory; -import io.sphere.sdk.client.SphereClient; -import io.sphere.sdk.client.SphereClientFactory; +import io.sphere.sdk.client.*; import io.sphere.sdk.products.ProductProjection; import io.sphere.sdk.products.queries.ProductProjectionQuery; import io.sphere.sdk.projects.queries.ProjectGet; @@ -46,6 +43,8 @@ public static class ClientState { private BlockingSphereClient sphereClient; + private BlockingSphereClient sphereApacheClient; + private BlockingSphereClient compatClient; private BlockingSphereClient compatOkHttpClient; @@ -89,6 +88,13 @@ public void init() { sphereClient = BlockingSphereClient.of(client, Duration.ofSeconds(10)); + final SphereClientFactory apacheFactory = SphereClientFactory.of(SphereApacheHttpClientFactory::create); + final SphereClient apacheClient = apacheFactory.createClient(getProjectKey(), //replace with your project key + getClientId(), //replace with your client id + getClientSecret()); //replace with your client secret + + sphereApacheClient = BlockingSphereClient.of(apacheClient, Duration.ofSeconds(10)); + compatClient = BlockingSphereClient.of(CompatSphereClient.of(ahcApiRoot), Duration.ofSeconds(10)); compatOkHttpClient = BlockingSphereClient.of(CompatSphereClient.of(okhttpApiRoot), Duration.ofSeconds(10)); @@ -205,6 +211,11 @@ public void retrieveProjectV1_AHC(ClientState state) { state.sphereClient.executeBlocking(ProjectGet.of()); } + @Benchmark + public void retrieveProjectV1_Apache(ClientState state) { + state.sphereApacheClient.executeBlocking(ProjectGet.of()); + } + @Benchmark public void retrieveProjectV2_Compat(ClientState state) { state.compatClient.executeBlocking(ProjectGet.of()); @@ -236,6 +247,13 @@ public void retrieveProductsV1_AHC(ClientState state) { Assertions.assertThat(response.getCount()).isEqualTo(100); } + @Benchmark + public void retrieveProductsV1_Apache(ClientState state) { + final PagedQueryResult response = state.sphereApacheClient + .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + Assertions.assertThat(response.getCount()).isEqualTo(100); + } + @Benchmark public void retrieveProductsV2_AHC(ClientState state) { final ApiHttpResponse response = state.ahcApiRoot.productProjections() From 473bb623a513e7f636ee190d119d3bcd25b004c7 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 25 Jan 2023 22:07:34 +0100 Subject: [PATCH 10/11] close sphere apache client --- .../jmh/java/com/commercetools/benchmark/ClientBenchmark.java | 1 + 1 file changed, 1 insertion(+) diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index 094225c99be..c551f4f34e1 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -114,6 +114,7 @@ public void tearDown() { compatClient.close(); compatOkHttpClient.close(); apacheApiRoot.close(); + sphereApacheClient.close(); okhttpApiRoot.close(); sphereClient.close(); } From 15a8daea4c939bfc6bde2ee3d0f3f05afee32405 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Thu, 26 Jan 2023 08:53:39 +0100 Subject: [PATCH 11/11] add apache product benchmark reorder benchmarks --- .../benchmark/ClientBenchmark.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java index c551f4f34e1..cf6753ff676 100644 --- a/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java +++ b/commercetools/commercetools-sdk-compat-v1/src/jmh/java/com/commercetools/benchmark/ClientBenchmark.java @@ -49,6 +49,8 @@ public static class ClientState { private BlockingSphereClient compatOkHttpClient; + private BlockingSphereClient compatApacheClient; + private List productsList; private TaxCategory taxCategory; @@ -99,6 +101,8 @@ public void init() { compatOkHttpClient = BlockingSphereClient.of(CompatSphereClient.of(okhttpApiRoot), Duration.ofSeconds(10)); + compatApacheClient = BlockingSphereClient.of(CompatSphereClient.of(apacheApiRoot), Duration.ofSeconds(10)); + productType = createProductType(); taxCategory = createTaxCategory(); @@ -113,6 +117,7 @@ public void tearDown() { ahcApiRoot.close(); compatClient.close(); compatOkHttpClient.close(); + compatApacheClient.close(); apacheApiRoot.close(); sphereApacheClient.close(); okhttpApiRoot.close(); @@ -228,24 +233,28 @@ public void retrieveProjectV2_CompatOkHttp(ClientState state) { } @Benchmark - public void retrieveProductsV2_CompatAHC(ClientState state) { - final PagedQueryResult response = state.compatClient + public void retrieveProductsV1_AHC(ClientState state) { + final PagedQueryResult response = state.sphereClient .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); Assertions.assertThat(response.getCount()).isEqualTo(100); } @Benchmark - public void retrieveProductsV2_CompatOkHttp(ClientState state) { - final PagedQueryResult response = state.compatOkHttpClient + public void retrieveProductsV2_CompatAHC(ClientState state) { + final PagedQueryResult response = state.compatClient .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); Assertions.assertThat(response.getCount()).isEqualTo(100); } @Benchmark - public void retrieveProductsV1_AHC(ClientState state) { - final PagedQueryResult response = state.sphereClient - .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); - Assertions.assertThat(response.getCount()).isEqualTo(100); + public void retrieveProductsV2_AHC(ClientState state) { + final ApiHttpResponse response = state.ahcApiRoot.productProjections() + .get() + .withStaged(true) + .withLimit(100) + .executeBlocking(); + Assertions.assertThat(response.getBody().getCount()).isEqualTo(100); + } @Benchmark @@ -256,14 +265,28 @@ public void retrieveProductsV1_Apache(ClientState state) { } @Benchmark - public void retrieveProductsV2_AHC(ClientState state) { - final ApiHttpResponse response = state.ahcApiRoot.productProjections() + public void retrieveProductsV2_CompatApache(ClientState state) { + final PagedQueryResult response = state.compatApacheClient + .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + Assertions.assertThat(response.getCount()).isEqualTo(100); + } + + @Benchmark + public void retrieveProductsV2_Apache(ClientState state) { + final ApiHttpResponse response = state.apacheApiRoot.productProjections() .get() .withStaged(true) .withLimit(100) .executeBlocking(); + Assertions.assertThat(response.getBody().getCount()).isEqualTo(100); + } + @Benchmark + public void retrieveProductsV2_CompatOkHttp(ClientState state) { + final PagedQueryResult response = state.compatOkHttpClient + .executeBlocking(ProductProjectionQuery.ofStaged().withLimit(100)); + Assertions.assertThat(response.getCount()).isEqualTo(100); } @Benchmark