Skip to content

Commit

Permalink
New round of spring optimizations
Browse files Browse the repository at this point in the history
- Upgrade to Spring Boot 3.3.4
- Remove the JPA variant that is not competitive and
  introduces additional processing not needed in
  other variants
- Use batched update in the JDBC variant (compliant with
  the test requirements)
- Set Hikari maximum pool size to 256
- Switch to jstachio for view rendering
  • Loading branch information
sdeleuze committed Sep 21, 2024
1 parent db30328 commit 67ea66c
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 311 deletions.
4 changes: 1 addition & 3 deletions frameworks/Java/spring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

This is the Spring MVC portion of a [benchmarking test suite](../) comparing a variety of web development platforms.

An embedded undertow is used for the web server, with nearly everything configured with default settings.
The only thing changed is Hikari can use up to (2 * cores count) connections (the default is 10).
See [About-Pool-Sizing](https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing)
An embedded undertow is used for the web server.

There are two implementations :
* For postgresql access, JdbcTemplate is used. See [JdbcDbRepository](src/main/java/hello/JdbcDbRepository.java).
Expand Down
21 changes: 0 additions & 21 deletions frameworks/Java/spring/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,6 @@
"notes": "",
"versus": ""
},
"jpa": {
"db_url": "/db",
"query_url": "/queries?queries=",
"fortune_url": "/fortunes",
"update_url": "/updates?queries=",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "Postgres",
"framework": "spring",
"language": "Java",
"flavor": "None",
"orm": "Full",
"platform": "Servlet",
"webserver": "Undertow",
"os": "Linux",
"database_os": "Linux",
"display_name": "spring-jpa",
"notes": "",
"versus": "spring"
},
"mongo": {
"db_url": "/db",
"query_url": "/queries?queries=",
Expand Down
26 changes: 22 additions & 4 deletions frameworks/Java/spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<version>3.3.4</version>
</parent>

<properties>
<java.version>21</java.version>
<jstachio.version>1.3.6</jstachio.version>
</properties>

<dependencies>
Expand All @@ -35,15 +36,23 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
<groupId>io.jstach</groupId>
<artifactId>jstachio</artifactId>
<version>${jstachio.version}</version>
</dependency>
<dependency>
<groupId>io.jstach</groupId>
<artifactId>jstachio-apt</artifactId>
<version>${jstachio.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
Expand All @@ -61,6 +70,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.jstach</groupId>
<artifactId>jstachio-apt</artifactId>
<version>${jstachio.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
15 changes: 0 additions & 15 deletions frameworks/Java/spring/spring-jpa.dockerfile

This file was deleted.

21 changes: 2 additions & 19 deletions frameworks/Java/spring/src/main/java/hello/App.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package hello;

import javax.sql.DataSource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.EventListener;

import com.zaxxer.hikari.HikariDataSource;

@SpringBootApplication
public class App {

Expand All @@ -20,18 +13,8 @@ public static void main(String[] args) {
}

@EventListener(ApplicationReadyEvent.class)
public void runAfterStartup() {
System.out.println("Application is ready");
}

@Bean
@Profile({ "jdbc", "jpa" })
DataSource datasource(DataSourceProperties dataSourceProperties) {
HikariDataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class)
.build();
dataSource.setMaximumPoolSize(Runtime.getRuntime().availableProcessors() * 2);

return dataSource;
public void runAfterStartup() {
System.out.println("Application is ready");
}

}
12 changes: 0 additions & 12 deletions frameworks/Java/spring/src/main/java/hello/JpaConfig.java

This file was deleted.

This file was deleted.

This file was deleted.

19 changes: 19 additions & 0 deletions frameworks/Java/spring/src/main/java/hello/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hello;

import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;

abstract public class Utils {

private static final int MIN_WORLD_NUMBER = 1;
private static final int MAX_WORLD_NUMBER_PLUS_ONE = 10_001;

public static int randomWorldNumber() {
return ThreadLocalRandom.current().nextInt(MIN_WORLD_NUMBER, MAX_WORLD_NUMBER_PLUS_ONE);
}

public static IntStream randomWorldNumbers() {
return ThreadLocalRandom.current().ints(MIN_WORLD_NUMBER, MAX_WORLD_NUMBER_PLUS_ONE).distinct();
}

}

This file was deleted.

This file was deleted.

This file was deleted.

26 changes: 9 additions & 17 deletions frameworks/Java/spring/src/main/java/hello/model/Fortune.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
package hello.model;

import jakarta.persistence.Entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Document
@Entity
public final class Fortune {
public final class Fortune implements Comparable<Fortune>{

@Id
@jakarta.persistence.Id
public int id;
@Field("message")
public String message;
public final int id;

protected Fortune() {
}
@Field("message")
public final String message;

public Fortune(int id, String message) {
this.id = id;
this.message = message;
}

public int getId() {
return id;
}

public String getMessage() {
return message;
@Override
public int compareTo(final Fortune other) {
return message.compareTo(other.message);
}
}
}
15 changes: 0 additions & 15 deletions frameworks/Java/spring/src/main/java/hello/model/Message.java

This file was deleted.

14 changes: 5 additions & 9 deletions frameworks/Java/spring/src/main/java/hello/model/World.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package hello.model;

import jakarta.persistence.Entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

@Document
@Entity
public final class World {

@Id
@jakarta.persistence.Id
public int id;

@Field("randomNumber")
public int randomnumber;
public int randomNumber;

protected World() {
}

public World(int id, int randomnumber) {
public World(int id, int randomNumber) {
this.id = id;
this.randomnumber = randomnumber;
this.randomNumber = randomNumber;
}

}
Loading

0 comments on commit 67ea66c

Please sign in to comment.