Does exposed have connection polling functionality...
# exposed
m
Does exposed have connection polling functionality like pgbouncer
a
ORMs don't need to pool connections because it's usually the responsibility of the JDBC DataSource. You can use HikariCP to add connection pooling. It supports just about any database, and can be slotted into any ORM that accepts a DataSource.
Copy code
val ds = HikariDataSource(hikariConfig)
val db = Database.connect(ds)
https://github.com/brettwooldridge/HikariCP#rocket-initialization
👍 1
r
How many connections will Exposed create without HikariCP or any pooling configuration? One for whole application? Or one for every inTransaction call?
a
Someone who knows better should correct me, but Exposed doesn't care whether the underlying DataSource is a connection pool or not. It will always ask the DataSource for a new connection for every transaction, and it's up to the DataSource how to do it. Delegation by composition! If the DataSource is a connection pool, then the pool will serve a cached connection if available. Otherwise, it will open a new one up to the pool limit. If the limit has been reached, it will wait for a connection to be available. If the DataSource is for the underlying JDBC driver, then it will always open a new connection to the database. There are connection pool proxies that exist (like Amazon RDS Proxy), which delegate the connection pooling to the proxy. You simply point your standard DataSource to the proxy rather than the database. I believe this is faster than asking the database for a new connection if the overhead of an in-app connection pool is undesirable, or if you want to optimize the total number of open connections, like in a swarm of tiny or ephemeral containers (like Docker or Serverless).
204 Views