Spring Data REST - 对DB的前10次调用非常慢。

问题描述 投票:0回答:1

...is parent POM of

Parent project

(Spring Boot

...is parent POM of

Subproject

-> has

  1. Parent project

    as a dependency

  2. Expected and actual resultsI've tried to create (via HTTP POST, using the REST API) several instances of the same entity in both projects. Using

Parent project

  1. , the entities get created in about 0.1 seconds, consistently. But in

    Subproject

  2. , the first 10 - and consistently exactly 10 - HTTP calls (both POST and GET) are really slow, up to 10 seconds per request, for the exact same entity. Expected behaviour is to see the same speeds from the first call.After these first 10 requests, performance is similar to the parent project.I have no clue as to why this behaviour is happening. If anyone has a suggestion, it will be greatly appreciated!

Problem description After launching my Spring Boot application, connected to a Postgres database via JPA项目设置和配置我有一个父项目 "模板",通过它,一个通用的领域模型被提供给子项目。然后,这些模型在每个子项目中都可以使用,包括父项目中的所有其他bean。设置是这样的。对于父项目

我自己的通用父项目POM(使用spring-boot-starter-parent和其他依赖关系)。

Spring Data REST,提供通用Bean)

对于子项目。
java hibernate spring-boot spring-data spring-data-rest
1个回答
0
投票

我已经通过查看Hibernate执行的SQL查询解决了这个问题。我当时使用的是InheritanceType.TABLE_PER_CLASS。正因为如此--很多在线文档也提到了--在处理大量实体类型时,可能会严重消耗性能,我的情况就是这样,通过扩展基础项目。不得不执行过多的UNION和JOIN查询。通过切换到InheritanceType.SINGLE_TABLE,它的工作速度又快了起来。

© www.soinside.com 2019 - 2024. All rights reserved.