diff --git a/pom.xml b/pom.xml index eb924c05..b44dea52 100644 --- a/pom.xml +++ b/pom.xml @@ -90,6 +90,7 @@ limitations under the License. + org.springframework spring-framework-bom @@ -133,8 +134,9 @@ limitations under the License. - spring-modulith-integration-test + spring-modulith-benchmarks spring-modulith-examples + spring-modulith-integration-test @@ -166,6 +168,7 @@ limitations under the License. prepare-release + spring-modulith-benchmarks spring-modulith-distribution spring-modulith-examples spring-modulith-integration-test diff --git a/spring-modulith-benchmarks/pom.xml b/spring-modulith-benchmarks/pom.xml new file mode 100644 index 00000000..abc77a94 --- /dev/null +++ b/spring-modulith-benchmarks/pom.xml @@ -0,0 +1,95 @@ + + 4.0.0 + + + org.springframework.modulith + spring-modulith + 1.4.0-SNAPSHOT + + + Spring Modulith - Benchmarks + spring-modulith-benchmarks + + + 1.37 + + 5.11.4 + true + org.springframework.modulith.benchmark + + + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + + + + + + org.springframework.modulith + spring-modulith-events-core + 1.3.4 + test + + + + org.junit.jupiter + junit-jupiter + test + + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + provided + + + + com.github.mp911de.microbenchmark-runner + microbenchmark-runner-junit5 + 0.4.0.RELEASE + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + + + + + + + + + + jitpack.io + https://jitpack.io + + + + \ No newline at end of file diff --git a/spring-modulith-benchmarks/src/test/java/org/springframework/modulith/events/core/PublicationsInProgressBenchmarks.java b/spring-modulith-benchmarks/src/test/java/org/springframework/modulith/events/core/PublicationsInProgressBenchmarks.java new file mode 100644 index 00000000..5ab9fa12 --- /dev/null +++ b/spring-modulith-benchmarks/src/test/java/org/springframework/modulith/events/core/PublicationsInProgressBenchmarks.java @@ -0,0 +1,106 @@ +/* + * Copyright 2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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. + */ +package org.springframework.modulith.events.core; + +import jmh.mbr.junit5.Microbenchmark; +import lombok.Value; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; +import org.springframework.modulith.events.core.DefaultEventPublicationRegistry.PublicationsInProgress; + +/** + * @author Oliver Drotbohm + */ +@Warmup(iterations = 10, time = 2) +@Measurement(iterations = 10, time = 2) +@Microbenchmark +public class PublicationsInProgressBenchmarks { + + @State(Scope.Benchmark) + public static class Fixture implements Iterable { + + private static final int NUMBER = 100; + + private final List events = new ArrayList<>(); + private final List identifiers = new ArrayList<>(); + private final List randomPublications = new ArrayList<>(); + + PublicationsInProgress inProgress; + + public Fixture() { + + this.inProgress = new DefaultEventPublicationRegistry.PublicationsInProgress(); + + for (int i = 0; i < NUMBER; i++) { + + var event = new Event(UUID.randomUUID().toString()); + + for (int j = 0; j < NUMBER; j++) { + + var identifier = PublicationTargetIdentifier.of(UUID.randomUUID().toString()); + + events.add(event); + identifiers.add(identifier); + + inProgress.register(TargetEventPublication.of(event, identifier)); + } + } + + var random = new Random(); + + for (int i = 0; i < NUMBER; i++) { + + var event = events.get(random.nextInt(NUMBER)); + var id = identifiers.get(random.nextInt(NUMBER)); + + randomPublications.add(TargetEventPublication.of(event, id)); + } + } + + /* + * (non-Javadoc) + * @see java.lang.Iterable#iterator() + */ + @Override + public Iterator iterator() { + return randomPublications.iterator(); + } + + @Value + static class Event { + String value; + } + } + + @Benchmark + public void inProgressPublicationsAccess(Fixture fixture, Blackhole sink) { + + for (TargetEventPublication publication : fixture) { + sink.consume(fixture.inProgress.getPublication(publication.getEvent(), publication.getTargetIdentifier())); + } + } +}