【问题标题】:Why does Hibernate Search app take so much time to start?为什么 Hibernate Search 应用程序需要这么长时间才能启动?
【发布时间】:2022-08-22 20:17:42
【问题描述】:

我正在使用 Hibernate Search 5.11.10 Final 和 Lucene 开发 Spring Boot 应用程序。启动应用程序最多需要 2 分钟:

2022-07-25 14:53:05.381  INFO 16884 --- [  restartedMain] zuers.Application          : Starting Application using Java 11.0.14.1 on CVDE043 with PID 16884 (C:\\blablapath\\target\\classes started by ladybug in C:\\blablapath)
2022-07-25 14:53:05.381  INFO 16884 --- [  restartedMain] zuers.Application          : No active profile set, falling back to default profiles: default
2022-07-25 14:53:05.426  INFO 16884 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set \'spring.devtools.add-properties\' to \'false\' to disable
2022-07-25 14:53:05.426  INFO 16884 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the \'logging.level.web\' property to \'DEBUG\'
2022-07-25 14:53:06.166  INFO 16884 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-07-25 14:53:06.224  INFO 16884 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 49 ms. Found 1 JPA repository interfaces.
2022-07-25 14:53:06.795  INFO 16884 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2022-07-25 14:53:06.805  INFO 16884 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-07-25 14:53:06.806  INFO 16884 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.54]
2022-07-25 14:53:06.900  INFO 16884 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-07-25 14:53:06.901  INFO 16884 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1474 ms
2022-07-25 14:53:06.927  INFO 16884 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-07-25 14:53:07.213  INFO 16884 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2022-07-25 14:53:07.220  INFO 16884 --- [  restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at \'/h2-console\'. Database available at \'jdbc:h2:~/zuers-db-komplett\'
2022-07-25 14:53:07.400  INFO 16884 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-07-25 14:53:07.488  INFO 16884 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.32.Final
2022-07-25 14:53:07.653  INFO 16884 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-07-25 14:53:07.870  INFO 16884 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-07-25 14:53:08.307  INFO 16884 --- [  restartedMain] org.hibernate.search.engine.Version      : HSEARCH000034: Hibernate Search 5.11.10.Final
2022-07-25 14:54:59.745  INFO 16884 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-07-25 14:55:00.155  INFO 16884 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit \'default\'
2022-07-25 14:55:00.838  WARN 16884 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-07-25 14:55:01.424  WARN 16884 --- [  restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2022-07-25 14:55:01.567  INFO 16884 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2022-07-25 14:55:01.605  INFO 16884 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8081 (http) with context path \'\'
2022-07-25 14:55:01.614  INFO 16884 --- [  restartedMain] zuers.Application          : Started Application in 116.603 seconds (JVM running for 117.676)

我的问题是:HSEARCH000034: Hibernate Search 5.11.10.FinalHHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]?有什么办法可以让这家初创公司走得更快?

这是我的applications.properties:

server.port=8081
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:~/zuers-db-komplett;AUTO_SERVER=TRUE
spring.jpa.properties.hibernate.search.lucene_version LATEST
spring.jpa.properties.hibernate.search.default.directory_provider = filesystem
spring.jpa.properties.hibernate.search.default.indexBase = ./var/lucene/indexes
spring.jpa.properties.hibernate.search.indexing_strategy = manual
spring.jpa.properties.hibernate.search.lucene.analysis_definition_provider = zuers.analyzer.AnalyzerProvider
spring.jpa.properties.hibernate.search.analyzer= strasseAnalyzer

注意:我正在使用的数据库大小为 4GB

    标签: spring-boot hibernate jpa lucene hibernate-search


    【解决方案1】:

    在应用程序启动期间,Lucene 索引器将在文件系统位置创建或更新索引:

    /var/lucene/indexes

    基本上有两个影响可能是观察到的时间损失的原因:

    • (一个) 数据源的大小,即要处理的元组和/或属性的数量,或
    • (b) 您正在读取或写入的文件系统的 IO 吞吐量。

    考虑检查 IO 瓶颈 (b),如果可以排除您没有使用(大量)数据重新创建索引 (a)每次应用程序启动。正如documentation 警告的那样,请记住

    重新索引是一项可能需要长时间运行的任务,应显式触发。要使用数据库中预先存在的数据填充索引,请使用海量索引。

    然后

    删除模式意味着丢失索引数据。

    最有可能的是,您的自定义或manual 索引策略执行上述操作之一:每次应用程序启动时。

    注意:其他答案中的提示@yrodiere应该指导您排除此选项。

    【讨论】:

      【解决方案2】:

      怎么了

      如果没有复制器,很难确定。

      我建议尝试使用此属性启动您的应用程序:

      spring.jpa.properties.hibernate.search.autoregister_listeners = false
      

      不要被这个属性的(非常糟糕的)名称所迷惑:它与侦听器无关,实际上它只是完全禁用了 Hibernate Search。

      请注意,此属性在 Hibernate Search 6 中被重命名为 hibernate.search.enabled(您绝对应该考虑使用 upgrading to)。

      如果设置此属性后,您的应用程序启动仍然很慢,那么您的问题与 Hibernate Search 无关,因此您可以调查其他线索(数据库访问速度慢?)。

      另一方面,如果这解决了您的性能问题,那么肯定是 Hibernate Search 很慢。这很奇怪,因为 Hibernate Search 在启动时实际上很少占用资源。我能想象的最糟糕的是 Hibernate Search 试图在文件系统上创建许多索引,比如数百个索引,如果你的应用程序中有数百个索引实体类型。但是,如果您的文件系统一开始就很慢,那只会很慢……也许您的索引在网络共享上?

      除此之外,我不确定。尝试将org.hibernate.search 类别的日志级别设置为TRACE,也许?

      【讨论】:

        【解决方案3】:

        感谢@yrodiere 和@MWiesner 的帮助!它帮助我理解了 Hibernate 的工作原理。

        遇到这个问题后,我的问题就解决了:Why HSQLDialect initialization takes so long in a spring boot project?

        更改我的 application.properties 文件后,应用程序现在在几秒钟内启动:

        spring.jpa.hibernate.ddl-auto=none
        

        【讨论】:

          猜你喜欢
          • 2020-09-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-08-28
          • 1970-01-01
          • 2020-02-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多