title: Spring Boot 2. Hikari Connection Pool optimization
body: <p>I have a SpringBoot app, I was making some performance test in the controller, and I realized that whatever is the first query I put the controller, It take ages compare to the others... (ths DB is a remote connection, but I can't change this)</p>
  
  <pre><code>long t1 = System.nanoTime();
  
  menuPriceSummaryService.findAllVegan().stream();            
  
  long t2 = System.nanoTime();
  long elapsedTimeInSeconds = (t2 - t1) / 1000000000;
  System.out.println("elapsedTimeInSeconds1 -&gt; " +  elapsedTimeInSeconds);
  
  t1 = System.nanoTime();
  
  menuPriceSummaryService.findAllVegan();
  
  t2 = System.nanoTime();
  elapsedTimeInSeconds = (t2 - t1) / 1000000000;
  System.out.println("elapsedTimeInSeconds2 -&gt; " +  elapsedTimeInSeconds);
  
  t1 = System.nanoTime();
  menuPriceSummaryService.findAllVegan().parallelStream();
  t2 = System.nanoTime();
  elapsedTimeInSeconds = (t2 - t1) / 1000000000;
  System.out.println("elapsedTimeInSeconds3 -&gt; " +  elapsedTimeInSeconds);
  
  t1 = System.nanoTime();
  menuPriceSummaryService.findAllVegan().parallelStream().filter(this::notInMyFavourites);
  t2 = System.nanoTime();
  elapsedTimeInSeconds = (t2 - t1) / 1000000000;
  </code></pre>
  
  <p>the time:</p>
  
  <pre><code>elapsedTimeInSeconds1 -&gt; 76
  elapsedTimeInSeconds2 -&gt; 0
  elapsedTimeInSeconds3 -&gt; 0
  elapsedTimeInSeconds4 -&gt; 0
  </code></pre>
  
  <p>Is it normal?
  Is there is something I can do configuring the Hikari pool to optimize this?</p>
  
  <p>the pom.xml</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.h2database&lt;/groupId&gt;
      &lt;artifactId&gt;h2&lt;/artifactId&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
      &lt;scope&gt;runtime&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>the application.properties:</p>
  
  <pre><code>spring.datasource.url=jdbc:mysql://elcordelaciutat.awob1oxhu1so.eu-central-1.rds.amazonaws.com:3306/elcor
  spring.datasource.username=elcor
  spring.datasource.password=elcor2#$
  
  spring.jpa.show-sql=false
  spring.jpa.properties.hibernate.format_sql=true
  hibernate.dialect=org.hibernate.dialect.MySQLDialect
  </code></pre>