Arjan van Wieringen
07/02/2023, 12:35 PMArjan van Wieringen
07/02/2023, 12:36 PMval dataSource = PGPoolingDataSource().apply {
serverNames = arrayOf(databaseHost)
portNumbers = intArrayOf(databasePort)
user = databaseUser
password = databasePassword
this.databaseName = databaseName
maxConnections = 1
initialConnections = 1
}
vs
val dataSource = PGSimpleDataSource().apply {
serverNames = arrayOf(databaseHost)
portNumbers = intArrayOf(databasePort)
user = databaseUser
password = databasePassword
this.databaseName = databaseName
}
Actual code:
while (limit == null || count < limit) {
newSuspendedTransaction(db = db) {
Events.insert {
it[id] = java.util.UUID.randomUUID()
it[type] = "test"
it[payload] = "test"
}
count++
delay(delay?.toLong() ?: 0)
if (count % 1000 == 0) println("ClientId ${clientId} : Produced $count events")
}
}
Andreas Scheja
07/14/2023, 8:51 PMPGSimpleDataSource
is opening a new connection every time you ask for one while PGPoolingDataSource
will probably keep the same connection open and reuse it