Quellcode durchsuchen

Update Spring benchmarks (#7749)

Christoph Dreis vor 2 Jahren
Ursprung
Commit
6315ed102e

+ 2 - 4
frameworks/Java/spring/README.md

@@ -36,10 +36,8 @@ There are two implementations :
 
 ## Versions
 
-* [OpenJDK Runtime Environment Temurin-11.0.16+8 (build 11.0.16+8)](https://adoptium.net/es/temurin/releases/?version=11)
-* [Spring boot 2.6.9](https://spring.io/projects/spring-boot)
-
-The change to use OpenJDK Temurin is inspired in [whichjdk](https://whichjdk.com/) page advice.
+* [OpenJDK Runtime Environment Temurin-17](https://adoptium.net/es/temurin/releases/?version=17)
+* [Spring-Boot 3.0.0](https://spring.io/projects/spring-boot)
 
 ## Test URLs
 

+ 6 - 6
frameworks/Java/spring/benchmark_config.json

@@ -16,8 +16,8 @@
       "language": "Java",
       "flavor": "None",
       "orm": "Micro",
-      "platform": "Tomcat",
-      "webserver": "None",
+      "platform": "Servlet",
+      "webserver": "Undertow",
       "os": "Linux",
       "database_os": "Linux",
       "display_name": "spring-jdbc",
@@ -37,8 +37,8 @@
       "language": "Java",
       "flavor": "None",
       "orm": "Full",
-      "platform": "Tomcat",
-      "webserver": "None",
+      "platform": "Servlet",
+      "webserver": "Undertow",
       "os": "Linux",
       "database_os": "Linux",
       "display_name": "spring-jpa",
@@ -58,8 +58,8 @@
       "language": "Java",
       "flavor": "None",
       "orm": "Full",
-      "platform": "Tomcat",
-      "webserver": "None",
+      "platform": "Servlet",
+      "webserver": "Undertow",
       "os": "Linux",
       "database_os": "Linux",
       "display_name": "spring-mongo",

+ 6 - 6
frameworks/Java/spring/config.toml

@@ -14,8 +14,8 @@ database = "Postgres"
 database_os = "Linux"
 os = "Linux"
 orm = "Micro"
-platform = "Tomcat"
-webserver = "None"
+platform = "Servlet"
+webserver = "Undertow"
 versus = ""
 
 [jpa]
@@ -29,8 +29,8 @@ database = "Postgres"
 database_os = "Linux"
 os = "Linux"
 orm = "Full"
-platform = "Tomcat"
-webserver = "None"
+platform = "Servlet"
+webserver = "Undertow"
 versus = "spring"
 
 [mongo]
@@ -44,6 +44,6 @@ database = "mongodb"
 database_os = "Linux"
 os = "Linux"
 orm = "Full"
-platform = "Tomcat"
-webserver = "None"
+platform = "Servlet"
+webserver = "Undertow"
 versus = "spring"

+ 3 - 3
frameworks/Java/spring/pom.xml

@@ -11,12 +11,12 @@
 	<parent>
 		<groupId>org.springframework.boot</groupId>
 		<artifactId>spring-boot-starter-parent</artifactId>
-		<version>2.6.9</version>
+		<version>3.0.0</version>
 	</parent>
 
 	<properties>
-		<java.version>11</java.version>
-		<postgresql.version>42.3.3</postgresql.version>
+		<java.version>17</java.version>
+		<postgresql.version>42.5.1</postgresql.version>
 	</properties>
 
 	<dependencies>

+ 3 - 3
frameworks/Java/spring/spring-jpa.dockerfile

@@ -1,4 +1,4 @@
-FROM eclipse-temurin:11 as jre-build
+FROM eclipse-temurin:17 as jre-build
 
 # Create a custom Java runtime
 RUN $JAVA_HOME/bin/jlink \
@@ -9,7 +9,7 @@ RUN $JAVA_HOME/bin/jlink \
          --compress=2 \
          --output /javaruntime
 
-FROM maven:3.6.1-jdk-11-slim as maven
+FROM maven:3.8.5-openjdk-17-slim as maven
 ENV JAVA_HOME=/opt/java/openjdk
 ENV PATH "${JAVA_HOME}/bin:${PATH}"
 COPY --from=jre-build /javaruntime $JAVA_HOME
@@ -20,7 +20,7 @@ COPY src src
 COPY pom.xml pom.xml
 RUN mvn package -q
 
-FROM debian:buster-slim
+FROM debian:bullseye-slim
 ENV JAVA_HOME=/opt/java/openjdk
 ENV PATH "${JAVA_HOME}/bin:${PATH}"
 COPY --from=jre-build /javaruntime $JAVA_HOME

+ 3 - 3
frameworks/Java/spring/spring-mongo.dockerfile

@@ -1,4 +1,4 @@
-FROM eclipse-temurin:11 as jre-build
+FROM eclipse-temurin:17 as jre-build
 
 # Create a custom Java runtime
 RUN $JAVA_HOME/bin/jlink \
@@ -9,7 +9,7 @@ RUN $JAVA_HOME/bin/jlink \
          --compress=2 \
          --output /javaruntime
 
-FROM maven:3.6.1-jdk-11-slim as maven
+FROM maven:3.8.5-openjdk-17-slim as maven
 ENV JAVA_HOME=/opt/java/openjdk
 ENV PATH "${JAVA_HOME}/bin:${PATH}"
 COPY --from=jre-build /javaruntime $JAVA_HOME
@@ -20,7 +20,7 @@ COPY src src
 COPY pom.xml pom.xml
 RUN mvn package -q
 
-FROM debian:buster-slim
+FROM debian:bullseye-slim
 ENV JAVA_HOME=/opt/java/openjdk
 ENV PATH "${JAVA_HOME}/bin:${PATH}"
 COPY --from=jre-build /javaruntime $JAVA_HOME

+ 3 - 3
frameworks/Java/spring/spring.dockerfile

@@ -1,4 +1,4 @@
-FROM eclipse-temurin:11 as jre-build
+FROM eclipse-temurin:17 as jre-build
 
 # Create a custom Java runtime
 RUN $JAVA_HOME/bin/jlink \
@@ -9,7 +9,7 @@ RUN $JAVA_HOME/bin/jlink \
          --compress=2 \
          --output /javaruntime
 
-FROM maven:3.6.1-jdk-11-slim as maven
+FROM maven:3.8.5-openjdk-17-slim as maven
 ENV JAVA_HOME=/opt/java/openjdk
 ENV PATH "${JAVA_HOME}/bin:${PATH}"
 COPY --from=jre-build /javaruntime $JAVA_HOME
@@ -20,7 +20,7 @@ COPY src src
 COPY pom.xml pom.xml
 RUN mvn package -q
 
-FROM debian:buster-slim
+FROM debian:bullseye-slim
 ENV JAVA_HOME=/opt/java/openjdk
 ENV PATH "${JAVA_HOME}/bin:${PATH}"
 COPY --from=jre-build /javaruntime $JAVA_HOME

+ 2 - 1
frameworks/Java/spring/src/main/java/hello/App.java

@@ -4,6 +4,7 @@ import javax.sql.DataSource;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
 import org.springframework.context.annotation.Bean;
@@ -11,7 +12,7 @@ import org.springframework.context.annotation.Profile;
 
 import com.zaxxer.hikari.HikariDataSource;
 
-@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
+@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, MongoRepositoriesAutoConfiguration.class})
 public class App {
 
 	public static void main(String[] args) {

+ 0 - 11
frameworks/Java/spring/src/main/java/hello/Config.java

@@ -1,11 +0,0 @@
-package hello;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
-import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
-
-@Configuration
-@EnableJpaRepositories("hello.jpa")
-@EnableMongoRepositories("hello.repository")
-public class Config {
-}

+ 12 - 0
frameworks/Java/spring/src/main/java/hello/JpaConfig.java

@@ -0,0 +1,12 @@
+package hello;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+@Profile("jpa")
+@Configuration
+@EnableJpaRepositories(basePackages = "hello.jpa")
+public class JpaConfig {
+
+}

+ 12 - 0
frameworks/Java/spring/src/main/java/hello/MongoConfig.java

@@ -0,0 +1,12 @@
+package hello;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
+
+@Profile("mongo")
+@Configuration
+@EnableMongoRepositories(basePackages = "hello.repository")
+public class MongoConfig {
+
+}

+ 14 - 7
frameworks/Java/spring/src/main/java/hello/controller/HelloController.java

@@ -6,6 +6,7 @@ import java.util.List;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.stream.IntStream;
 
+import jakarta.servlet.http.HttpServletResponse;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
@@ -25,29 +26,34 @@ public final class HelloController {
 		this.dbRepository = dbRepository;
 	}
 
-	@GetMapping(value = "/plaintext", produces = MediaType.TEXT_PLAIN_VALUE)
-	String plaintext() {
+	@GetMapping(value = "/plaintext")
+	String plaintext(HttpServletResponse response) {
+		response.setContentType(MediaType.TEXT_PLAIN_VALUE);
 		return "Hello, World!";
 	}
 
 	@GetMapping("/json")
-	Message json() {
+	Message json(HttpServletResponse response) {
+		response.setContentType(MediaType.APPLICATION_JSON_VALUE);
 		return new Message("Hello, World!");
 	}
 
 	@GetMapping("/db")
-	World db() {
+	World db(HttpServletResponse response) {
+		response.setContentType(MediaType.APPLICATION_JSON_VALUE);
 		return dbRepository.getWorld(randomWorldNumber());
 	}
 
 	@GetMapping("/queries")
-	World[] queries(@RequestParam(required = false) String queries) {
+	World[] queries(HttpServletResponse response, @RequestParam(required = false) String queries) {
+		response.setContentType(MediaType.APPLICATION_JSON_VALUE);
 		return randomWorldNumbers().mapToObj(dbRepository::getWorld).limit(parseQueryCount(queries))
 				.toArray(World[]::new);
 	}
 
 	@GetMapping("/updates")
-	World[] updates(@RequestParam(required = false) String queries) {
+	World[] updates(HttpServletResponse response, @RequestParam(required = false) String queries) {
+		response.setContentType(MediaType.APPLICATION_JSON_VALUE);
 		return randomWorldNumbers().mapToObj(dbRepository::getWorld).map(world -> {
 			// Ensure that the new random number is not equal to the old one.
 			// That would cause the JPA-based implementation to avoid sending the
@@ -71,7 +77,8 @@ public final class HelloController {
 
 	@GetMapping("/fortunes")
 	@ModelAttribute("fortunes")
-	List<Fortune> fortunes() {
+	List<Fortune> fortunes(HttpServletResponse response) {
+		response.setContentType(MediaType.TEXT_HTML_VALUE);
 		var fortunes = dbRepository.fortunes();
 
 		fortunes.add(new Fortune(0, "Additional fortune added at request time."));

+ 2 - 2
frameworks/Java/spring/src/main/java/hello/model/Fortune.java

@@ -1,6 +1,6 @@
 package hello.model;
 
-import javax.persistence.Entity;
+import jakarta.persistence.Entity;
 
 import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.mapping.Document;
@@ -10,7 +10,7 @@ import org.springframework.data.mongodb.core.mapping.Field;
 @Entity
 public final class Fortune {
 	@Id
-	@javax.persistence.Id
+	@jakarta.persistence.Id
 	public int id;
 	@Field("message")
 	public String message;

+ 2 - 2
frameworks/Java/spring/src/main/java/hello/model/World.java

@@ -1,6 +1,6 @@
 package hello.model;
 
-import javax.persistence.Entity;
+import jakarta.persistence.Entity;
 
 import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.mapping.Document;
@@ -11,7 +11,7 @@ import org.springframework.data.mongodb.core.mapping.Field;
 public final class World {
 
 	@Id
-	@javax.persistence.Id
+	@jakarta.persistence.Id
 	public int id;
 	@Field("randomNumber")
 	public int randomnumber;

+ 0 - 4
frameworks/Java/spring/src/main/java/hello/repository/JdbcDbRepository.java

@@ -2,8 +2,6 @@ package hello.repository;
 
 import java.util.List;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Profile;
 import org.springframework.dao.EmptyResultDataAccessException;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -15,7 +13,6 @@ import hello.model.World;
 @Repository
 @Profile("jdbc")
 public class JdbcDbRepository implements DbRepository {
-	private final Logger log = LoggerFactory.getLogger(getClass());
 	private final JdbcTemplate jdbcTemplate;
 
 	public JdbcDbRepository(JdbcTemplate jdbcTemplate) {
@@ -24,7 +21,6 @@ public class JdbcDbRepository implements DbRepository {
 
 	@Override
 	public World getWorld(int id) {
-		log.debug("getWorld({})", id);
 		try {
 			return jdbcTemplate.queryForObject("SELECT * FROM world WHERE id = ?",
 					(rs, rn) -> new World(rs.getInt("id"), rs.getInt("randomnumber")), id);

+ 0 - 4
frameworks/Java/spring/src/main/java/hello/repository/MongoDbRepository.java

@@ -2,8 +2,6 @@ package hello.repository;
 
 import java.util.List;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Profile;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.stereotype.Repository;
@@ -14,7 +12,6 @@ import hello.model.World;
 @Repository
 @Profile("mongo")
 public class MongoDbRepository implements DbRepository {
-	private final Logger log = LoggerFactory.getLogger(getClass());
 	private final MongoTemplate mongoTemplate;
 
 	public MongoDbRepository(MongoTemplate mongoTemplate) {
@@ -23,7 +20,6 @@ public class MongoDbRepository implements DbRepository {
 
 	@Override
 	public World getWorld(int id) {
-		log.debug("getWorld({})", id);
 		return mongoTemplate.findById(id, World.class);
 	}
 

+ 2 - 1
frameworks/Java/spring/src/main/resources/application.yml

@@ -40,4 +40,5 @@ spring:
   profiles:
     active: jdbc
 
-server.server-header: Spring
+server.server-header: Spring
+server.servlet.encoding.force: true