framework-benchmarks: Spring Boot 4.1.1 vs Quarkus 3.40.1 vs Micronaut 5.2.2, JVM + native, benchmarked
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.micronaut.platform</groupId>
|
||||
<artifactId>micronaut-parent</artifactId>
|
||||
<version>5.2.2</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.ankurm.benchmarks</groupId>
|
||||
<artifactId>micronaut-app</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>micronaut-app</name>
|
||||
<description>Widget REST API on Micronaut 5.2.2 - framework-benchmarks</description>
|
||||
|
||||
<properties>
|
||||
<packaging>jar</packaging>
|
||||
<jdk.version>25</jdk.version>
|
||||
<release.version>25</release.version>
|
||||
<micronaut.version>5.2.2</micronaut.version>
|
||||
<micronaut.runtime>netty</micronaut.runtime>
|
||||
<exec.mainClass>com.ankurm.benchmarks.micronaut.Application</exec.mainClass>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-http-server-netty</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micronaut.serde</groupId>
|
||||
<artifactId>micronaut-serde-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micronaut.validation</groupId>
|
||||
<artifactId>micronaut-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>micronaut-app</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.micronaut.maven</groupId>
|
||||
<artifactId>micronaut-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths combine.children="append">
|
||||
<path>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-http-validation</artifactId>
|
||||
<version>${micronaut.core.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>io.micronaut.validation</groupId>
|
||||
<artifactId>micronaut-validation-processor</artifactId>
|
||||
<version>${micronaut.validation.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>${exec.mainClass}</mainClass>
|
||||
</transformer>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||
</transformers>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<imageName>micronaut-app</imageName>
|
||||
<mainClass>${exec.mainClass}</mainClass>
|
||||
<buildArgs>
|
||||
<!-- Netty's ResourceLeakDetector holds a static reference to a
|
||||
ch.qos.logback.classic.Logger; logback is run-time-init by
|
||||
default, which GraalVM refuses to embed in the image heap.
|
||||
See docs/output/04-micronaut-native-build.txt for the real
|
||||
error this fixes. -->
|
||||
<buildArg>--initialize-at-run-time=io.netty</buildArg>
|
||||
</buildArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ankurm.benchmarks.micronaut;
|
||||
|
||||
import io.micronaut.runtime.Micronaut;
|
||||
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
Micronaut.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.ankurm.benchmarks.micronaut;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.PositiveOrZero;
|
||||
|
||||
@Serdeable
|
||||
public record CreateWidgetRequest(
|
||||
@NotBlank String name,
|
||||
@PositiveOrZero int quantity) {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ankurm.benchmarks.micronaut;
|
||||
|
||||
import io.micronaut.http.annotation.Controller;
|
||||
import io.micronaut.http.annotation.Get;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A plain custom endpoint rather than the micronaut-management starter, to keep the three
|
||||
* health checks comparably trivial instead of comparing three different libraries.
|
||||
*/
|
||||
@Controller("/health")
|
||||
public class HealthController {
|
||||
|
||||
@Get
|
||||
public Map<String, String> health() {
|
||||
return Map.of("status", "UP");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ankurm.benchmarks.micronaut;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
/**
|
||||
* The one domain type every app in this repo shares, field for field, across
|
||||
* Spring Boot, Quarkus and Micronaut. See the post's "the app under test" section.
|
||||
* {@code @Serdeable} is Micronaut's own compile-time (de)serialization annotation,
|
||||
* the equivalent of what Jackson's reflection does automatically at runtime for the
|
||||
* other two apps - this is itself one of the post's findings.
|
||||
*/
|
||||
@Serdeable
|
||||
public record Widget(String id, String name, int quantity) {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ankurm.benchmarks.micronaut;
|
||||
|
||||
import io.micronaut.http.HttpResponse;
|
||||
import io.micronaut.http.annotation.*;
|
||||
import io.micronaut.validation.Validated;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
|
||||
@Controller("/widgets")
|
||||
@Validated
|
||||
public class WidgetController {
|
||||
|
||||
private final WidgetStore store;
|
||||
|
||||
public WidgetController(WidgetStore store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
@Get
|
||||
public Collection<Widget> all() {
|
||||
return store.findAll();
|
||||
}
|
||||
|
||||
@Get("/{id}")
|
||||
public HttpResponse<Widget> one(@PathVariable String id) {
|
||||
return store.findById(id)
|
||||
.map(HttpResponse::ok)
|
||||
.orElseGet(() -> HttpResponse.notFound());
|
||||
}
|
||||
|
||||
@Post
|
||||
public HttpResponse<Widget> create(@Valid @Body CreateWidgetRequest request) {
|
||||
Widget created = store.create(request.name(), request.quantity());
|
||||
return HttpResponse.created(created, URI.create("/widgets/" + created.id()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.ankurm.benchmarks.micronaut;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Thread-safe in-memory store, seeded identically to the Spring Boot and Quarkus versions.
|
||||
* Deliberately no database: this repo isolates framework/runtime overhead from JDBC driver
|
||||
* and native-image reflection-metadata concerns, which is a separate, larger topic.
|
||||
*/
|
||||
@Singleton
|
||||
public class WidgetStore {
|
||||
|
||||
private final Map<String, Widget> widgets = new ConcurrentHashMap<>();
|
||||
private final AtomicInteger sequence = new AtomicInteger(0);
|
||||
|
||||
public WidgetStore() {
|
||||
seed("Hex Wrench Set", 42);
|
||||
seed("Torque Screwdriver", 17);
|
||||
seed("Bearing Puller", 5);
|
||||
seed("Digital Caliper", 23);
|
||||
seed("Bench Vise", 8);
|
||||
}
|
||||
|
||||
private void seed(String name, int quantity) {
|
||||
String id = "w-" + sequence.incrementAndGet();
|
||||
widgets.put(id, new Widget(id, name, quantity));
|
||||
}
|
||||
|
||||
public Collection<Widget> findAll() {
|
||||
return widgets.values();
|
||||
}
|
||||
|
||||
public Optional<Widget> findById(String id) {
|
||||
return Optional.ofNullable(widgets.get(id));
|
||||
}
|
||||
|
||||
public Widget create(String name, int quantity) {
|
||||
String id = "w-" + sequence.incrementAndGet();
|
||||
Widget widget = new Widget(id, name, quantity);
|
||||
widgets.put(id, widget);
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
micronaut.application.name=micronautApp
|
||||
micronaut.server.port=8083
|
||||
endpoints.health.enabled=true
|
||||
endpoints.health.sensitive=false
|
||||
@@ -0,0 +1,10 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user