ngbatis icon indicating copy to clipboard operation
ngbatis copied to clipboard

The problem and solution of the first query taking a long time. 第一次查询的性能问题及解决方法

Open CorvusYe opened this issue 7 months ago • 0 comments

第一种情况,查询语句组装耗时

在ngbatis对模板引擎的使用中,有一个比较重的资源使用了懒加载的方式。 日志输出对应的是:nGql make up costs 370ms,如果想把这部分时间挪到服务启动时, 可以在项目中使用以下方式,提前完成资源加载:

@Bean
public TextResolver textResolver(TextResolver resolver) {
  resolver.resolve("", Collections.emptyMap());
  return resolver;
}

第二种情况,执行查询的耗时

另外还有可能耗时的环节发生在数据库的查询上,日志输出对应的是:query costs 1091ms 如果最小连接数为 0,那么也会在第一次查询时创建连接,也会比单纯的查询本身额外消耗一些时间: 可以让最小连接数大于0,从而在服务启动时,完成连接创建,减少初次查询耗时。

nebula:
  pool-config:
    min-conns-size: 1

CorvusYe avatar Nov 22 '23 08:11 CorvusYe