Move Benchmarks from performance module into spring-data-jpa.
Closes #3655
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -58,12 +58,6 @@
|
||||
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>benchmark</id>
|
||||
<modules>
|
||||
<module>spring-data-jpa-performance</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>hibernate-62</id>
|
||||
<properties>
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
<?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>
|
||||
|
||||
<artifactId>spring-data-jpa-performance</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Spring Data JPA - Performance</name>
|
||||
<description>Benchmark build for Spring Data JPA</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa-parent</artifactId>
|
||||
<version>3.4.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<jmh.version>1.37</jmh.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
<version>${jakarta-annotation-api}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jakarta.persistence</groupId>
|
||||
<artifactId>jakarta.persistence-api</artifactId>
|
||||
<version>${jakarta-persistence-api}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${hibernate.groupId}.orm</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${hibernate}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${hibernate.groupId}.orm</groupId>
|
||||
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||
<version>${hibernate}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jakarta.xml.bind</groupId>
|
||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||
<version>${jaxb}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.mp911de.microbenchmark-runner</groupId>
|
||||
<artifactId>microbenchmark-runner-junit5</artifactId>
|
||||
<version>0.4.0.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>${h2}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.jsqlparser</groupId>
|
||||
<artifactId>jsqlparser</artifactId>
|
||||
<version>${jsqlparser}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Automatic-Module-Name>
|
||||
org.springframework.data.jpa.performance.tests
|
||||
</Automatic-Module-Name>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence https://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||
<persistence-unit name="benchmark">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>org.springframework.data.jpa.domain.AbstractPersistable</class>
|
||||
<class>org.springframework.data.jpa.domain.AbstractAuditable</class>
|
||||
<class>org.springframework.data.jpa.model.Person</class>
|
||||
<class>org.springframework.data.jpa.model.Profile</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework.data" level="error"/>
|
||||
|
||||
<!-- <logger name="org.hibernate.SQL" level="debug" />-->
|
||||
|
||||
<root level="error">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -351,6 +351,16 @@
|
||||
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||
<version>${hibernate}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${hibernate}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>jakarta.persistence</groupId>
|
||||
<artifactId>jakarta.persistence-api</artifactId>
|
||||
|
||||
@@ -13,23 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jpa.repository;
|
||||
package org.springframework.data.jpa.benchmark;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Persistence;
|
||||
import jakarta.persistence.Query;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jmh.mbr.junit5.Microbenchmark;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
import org.junit.platform.commons.annotation.Testable;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Level;
|
||||
@@ -42,21 +41,24 @@ import org.openjdk.jmh.annotations.Timeout;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.model.IPersonProjection;
|
||||
import org.springframework.data.jpa.model.Person;
|
||||
import org.springframework.data.jpa.model.Profile;
|
||||
import org.springframework.data.jpa.benchmark.model.IPersonProjection;
|
||||
import org.springframework.data.jpa.benchmark.model.Person;
|
||||
import org.springframework.data.jpa.benchmark.model.Profile;
|
||||
import org.springframework.data.jpa.benchmark.repository.PersonRepository;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Microbenchmark
|
||||
@Testable
|
||||
@Fork(1)
|
||||
@Warmup(time = 2, iterations = 3)
|
||||
@Measurement(time = 2)
|
||||
@Timeout(time = 2)
|
||||
public class RepositoryFinderTests {
|
||||
public class RepositoryFinderBenchmarks {
|
||||
|
||||
private static final String PERSON_FIRSTNAME = "first";
|
||||
private static final String COLUMN_PERSON_FIRSTNAME = "firstname";
|
||||
@@ -103,12 +105,23 @@ public class RepositoryFinderTests {
|
||||
|
||||
private void createEntityManager() {
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
|
||||
factoryBean.setPersistenceUnitName("benchmark");
|
||||
factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
|
||||
factoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
|
||||
factoryBean.setPersistenceXmlLocation("classpath*:META-INF/persistence-jmh.xml");
|
||||
factoryBean.setMappingResources("classpath*:META-INF/orm-jmh.xml");
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put("jakarta.persistence.jdbc.url", "jdbc:h2:mem:test");
|
||||
properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
|
||||
properties.put("hibernate.hbm2ddl.auto", "update");
|
||||
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("benchmark", properties);
|
||||
properties.put("hibernate.xml_mapping_enabled", "false");
|
||||
|
||||
factoryBean.setJpaProperties(properties);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
EntityManagerFactory entityManagerFactory = factoryBean.getObject();
|
||||
entityManager = entityManagerFactory.createEntityManager();
|
||||
}
|
||||
|
||||
@@ -139,7 +152,7 @@ public class RepositoryFinderTests {
|
||||
public List<Person> baselineEntityManagerHQLQuery(BenchmarkParameters parameters) {
|
||||
|
||||
Query query = parameters.entityManager
|
||||
.createQuery("SELECT p FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1");
|
||||
.createQuery("SELECT p FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1");
|
||||
query.setParameter(1, PERSON_FIRSTNAME);
|
||||
|
||||
return query.getResultList();
|
||||
@@ -148,7 +161,8 @@ public class RepositoryFinderTests {
|
||||
@Benchmark
|
||||
public Long baselineEntityManagerCount(BenchmarkParameters parameters) {
|
||||
|
||||
Query query = parameters.entityManager.createQuery("SELECT COUNT(*) FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1");
|
||||
Query query = parameters.entityManager.createQuery(
|
||||
"SELECT COUNT(*) FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1");
|
||||
query.setParameter(1, PERSON_FIRSTNAME);
|
||||
|
||||
return (Long) query.getSingleResult();
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jpa.model;
|
||||
package org.springframework.data.jpa.benchmark.model;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -13,9 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jpa.model;
|
||||
|
||||
import java.util.Set;
|
||||
package org.springframework.data.jpa.benchmark.model;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -25,6 +23,8 @@ import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jpa.model;
|
||||
package org.springframework.data.jpa.benchmark.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
@@ -13,13 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jpa.repository;
|
||||
package org.springframework.data.jpa.benchmark.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.model.IPersonProjection;
|
||||
import org.springframework.data.jpa.model.Person;
|
||||
import org.springframework.data.jpa.benchmark.model.IPersonProjection;
|
||||
import org.springframework.data.jpa.benchmark.model.Person;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.ListCrudRepository;
|
||||
|
||||
/**
|
||||
@@ -31,10 +32,10 @@ public interface PersonRepository extends ListCrudRepository<Person, Integer> {
|
||||
|
||||
List<IPersonProjection> findAllAndProjectToInterfaceByFirstname(String firstname);
|
||||
|
||||
@Query("SELECT p FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1")
|
||||
@Query("SELECT p FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1")
|
||||
List<Person> findAllWithAnnotatedQueryByFirstname(String firstname);
|
||||
|
||||
@Query("SELECT p FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1")
|
||||
@Query("SELECT p FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1")
|
||||
List<Person> findAllWithAnnotatedQueryByFirstname(String firstname, Sort sort);
|
||||
|
||||
@Query(value = "SELECT * FROM person WHERE firstname = ?1", nativeQuery = true)
|
||||
@@ -42,6 +43,6 @@ public interface PersonRepository extends ListCrudRepository<Person, Integer> {
|
||||
|
||||
Long countByFirstname(String firstname);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1")
|
||||
@Query("SELECT COUNT(*) FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1")
|
||||
Long countWithAnnotatedQueryByFirstname(String firstname);
|
||||
}
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.query;
|
||||
|
||||
import jmh.mbr.junit5.Microbenchmark;
|
||||
|
||||
import org.junit.platform.commons.annotation.Testable;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Level;
|
||||
@@ -32,12 +31,12 @@ import org.springframework.data.domain.Sort;
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Microbenchmark
|
||||
@Testable
|
||||
@Fork(1)
|
||||
@Warmup(time = 2, iterations = 3)
|
||||
@Measurement(time = 2)
|
||||
@Timeout(time = 2)
|
||||
public class HqlParserTests {
|
||||
public class HqlParserBenchmarks {
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
public static class BenchmarkParameters {
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.query;
|
||||
|
||||
import jmh.mbr.junit5.Microbenchmark;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.platform.commons.annotation.Testable;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Level;
|
||||
@@ -34,12 +33,12 @@ import org.springframework.data.domain.Sort;
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Microbenchmark
|
||||
@Testable
|
||||
@Fork(1)
|
||||
@Warmup(time = 2, iterations = 3)
|
||||
@Measurement(time = 2)
|
||||
@Timeout(time = 2)
|
||||
public class JSqlParserQueryEnhancerTests {
|
||||
public class JSqlParserQueryEnhancerBenchmarks {
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
public static class BenchmarkParameters {
|
||||
@@ -58,7 +57,6 @@ public class JSqlParserQueryEnhancerTests {
|
||||
union select SOME_COLUMN from SOME_OTHER_OTHER_TABLE""";
|
||||
|
||||
enhancer = new JSqlParserQueryEnhancer(DeclaredQuery.of(s, true));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2024 the original author or authors.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ https://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence https://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||
<persistence-unit name="benchmark">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>org.springframework.data.jpa.domain.AbstractPersistable</class>
|
||||
<class>org.springframework.data.jpa.domain.AbstractAuditable</class>
|
||||
<class>org.springframework.data.jpa.benchmark.model.Person</class>
|
||||
<class>org.springframework.data.jpa.benchmark.model.Profile</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
Reference in New Issue
Block a user