Reputation: 111
I have a spring boot application which has a controller. When I try to hit an API simultaneously (35 parrallel hits) it comes to the controller but there I am using findOne of the crudrepository which checks postgres for some data. The findOne functions returns in milliseconds but the next API doesn't get hold of postgres connection.
I am using HikariCp as the connection pooler with following settings
hikari:
idleTimeout: 10000
connectionTimeout: 60000
maximumPoolSize: 30
minimumIdle: 2
poolName: gor-srms
leakDetectionThreshold: 10000
In short at any point of time only 30 API's are working in parallel. Once the API is finished then only next one gets postgres connection.
Why is postgres connection not getting used for other API's since the findOne call only takes about millisecs to complete?
Adding the complete application properties:
server:
port: ${SERVER_PORT:${PORT:8093}}
contextPath: ${mdm.service.contextPath:/wms-masterdata}
spring:
application:
name: ${mdm.service.name:mdm-service}
jmx:
enabled: false
profiles:
active: local
cloud:
config:
discovery:
enabled: false
serviceId: config-server
jpa:
hibernate:
ddl-auto: validate
http:
multipart:
max-file-size: 20MB
max-request-size: 20MB
discovery:
enabled: true
eureka:
client:
enabled: ${discovery.enabled:true}
serviceUrl:
defaultZone: ${discovery.url:${REGISTRY_SERVICE_URL:http://localhost:8761}}/eureka/
instance:
metadataMap:
contextPath: ${server.contextPath}
db:
driver: org.postgresql.Driver
url: jdbc:postgresql://${database.ip:localhost}:5432/wms_masterdata
username: postgres
password: postgres
hikari:
idleTimeout: 10000
connectionTimeout: 60000
maximumPoolSize: 10
minimumIdle: 2
poolName: gor-mdm
leakDetectionThreshold: 60000
hibernate:
unit_name: wms_masterdata
show_sql: false
generate_ddl: false
entitymanager:
packagesToScan: com.gor.platform.mdm.service.model
butler:
url: https://192.168.8.116
management:
security:
enabled: false
health:
db:
enabled: false
security:
basic:
enabled: false
flyway:
baseline-on-migrate: true
enabled: true
ignore-ignored-migrations: true
Upvotes: 5
Views: 8968
Reputation: 111
I was finally able to solve this by setting spring.jpa.open-in-view=false
.
Be aware that this might lead to LazyInitialization Exception.
Upvotes: 2
Reputation: 512
spring.datasource.TYPE=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimumIdle=5
spring.datasource.hikari.maximumPoolSize=20
spring.datasource.hikari.idleTimeout=30000
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.testWhileIdle=true
spring.datasource.hikari.validationQuery=SELECT 1
spring.datasource.hikari.connectionTimeout=30000
Having this kind of setting help to have efficient connection pooling and allowed to server more traffic.
Upvotes: 1