Can someone explain to me why a pooled connection ...
# exposed
a
Can someone explain to me why a pooled connection (PGPoolingDataSource, although deprecated) with 1 connection count is much faster with multiple transactions, then a PGSimpleConnectionSource? I am running a while loop to produce a maximum amount of transactions. But the difference is almost 1000x.
👀 1
Copy code
val dataSource = PGPoolingDataSource().apply {
        serverNames = arrayOf(databaseHost)
        portNumbers = intArrayOf(databasePort)
        user = databaseUser
        password = databasePassword
        this.databaseName = databaseName
        maxConnections = 1
        initialConnections = 1
    }
vs
Copy code
val dataSource = PGSimpleDataSource().apply {
        serverNames = arrayOf(databaseHost)
        portNumbers = intArrayOf(databasePort)
        user = databaseUser
        password = databasePassword
        this.databaseName = databaseName
    }
Actual code:
Copy 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")
            }
        }
a
Not really familiar with both classes, but maybe it looks like
PGSimpleDataSource
is opening a new connection every time you ask for one while
PGPoolingDataSource
will probably keep the same connection open and reuse it