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,66 @@
|
||||
<?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>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>4.1.1</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.ankurm.benchmarks</groupId>
|
||||
<artifactId>spring-boot-app</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>spring-boot-app</name>
|
||||
<description>Widget REST API on Spring Boot 4.1.1 - framework-benchmarks</description>
|
||||
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>spring-boot-app</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.ankurm.benchmarks.springboot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class BenchmarkApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BenchmarkApplication.class, args);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.ankurm.benchmarks.springboot;
|
||||
|
||||
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.springboot;
|
||||
|
||||
/**
|
||||
* 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,37 @@
|
||||
package com.ankurm.benchmarks.springboot;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/widgets")
|
||||
public class WidgetController {
|
||||
|
||||
private final WidgetStore store;
|
||||
|
||||
public WidgetController(WidgetStore store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Collection<Widget> all() {
|
||||
return store.findAll();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Widget> one(@PathVariable String id) {
|
||||
return store.findById(id)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElseGet(() -> ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Widget> create(@Valid @RequestBody CreateWidgetRequest request) {
|
||||
Widget created = store.create(request.name(), request.quantity());
|
||||
return ResponseEntity.created(URI.create("/widgets/" + created.id())).body(created);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.ankurm.benchmarks.springboot;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
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 Quarkus 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.
|
||||
*/
|
||||
@Component
|
||||
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 @@
|
||||
server.port=8081
|
||||
spring.main.banner-mode=off
|
||||
management.endpoints.web.exposure.include=health
|
||||
logging.level.root=WARN
|
||||
Reference in New Issue
Block a user