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,87 @@
|
||||
<?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>
|
||||
|
||||
<groupId>com.ankurm.benchmarks</groupId>
|
||||
<artifactId>quarkus-app</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>quarkus-app</name>
|
||||
<description>Widget REST API on Quarkus 3.40.1 LTS - framework-benchmarks</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.release>25</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||
<quarkus.platform.version>3.40.1</quarkus.platform.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${quarkus.platform.group-id}</groupId>
|
||||
<artifactId>${quarkus.platform.artifact-id}</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-smallrye-health</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>quarkus-app</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>${quarkus.platform.group-id}</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>build</goal>
|
||||
<goal>generate-code</goal>
|
||||
<goal>generate-code-tests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<properties>
|
||||
<quarkus.package.jar.enabled>false</quarkus.package.jar.enabled>
|
||||
<quarkus.native.enabled>true</quarkus.native.enabled>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.ankurm.benchmarks.quarkus;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.PositiveOrZero;
|
||||
|
||||
public record CreateWidgetRequest(
|
||||
@NotBlank String name,
|
||||
@PositiveOrZero int quantity) {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.ankurm.benchmarks.quarkus;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public record Widget(String id, String name, int quantity) {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ankurm.benchmarks.quarkus;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
|
||||
@Path("/widgets")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class WidgetResource {
|
||||
|
||||
@Inject
|
||||
WidgetStore store;
|
||||
|
||||
@GET
|
||||
public Collection<Widget> all() {
|
||||
return store.findAll();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
public Response one(@PathParam("id") String id) {
|
||||
return store.findById(id)
|
||||
.map(w -> Response.ok(w).build())
|
||||
.orElseGet(() -> Response.status(Response.Status.NOT_FOUND).build());
|
||||
}
|
||||
|
||||
@POST
|
||||
public Response create(@Valid CreateWidgetRequest request) {
|
||||
Widget created = store.create(request.name(), request.quantity());
|
||||
return Response.created(URI.create("/widgets/" + created.id())).entity(created).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.ankurm.benchmarks.quarkus;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
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 Micronaut 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.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
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,3 @@
|
||||
quarkus.http.port=8082
|
||||
quarkus.banner.enabled=false
|
||||
quarkus.log.level=WARN
|
||||
Reference in New Issue
Block a user