typelevel / doobie

Functional JDBC layer for Scala.
MIT License
2.16k stars 356 forks source link

Set autoCommit=false for Hikari pool by default? #1244

Open skennedy opened 4 years ago

skennedy commented 4 years ago

In my app we use the doobie.hikari.HikariTransactor#newHikariTransactor constructor to build a Hikari transactor.

And we are seeing a lot of debug lines like so:

2020-08-07 04:49:46,900 DEBUG [c.z.h.p.PoolBase:240] HikariPool-1 - Reset (autoCommit) on connection xxx

This makes sense as doobie is setting autoCommit=false before every transaction, but default hikari configuration sets up connections as autoCommit=true. This means that hikari needs to reset connections to autoCommit=true after doobie has finished with them.

Stack overflow suggests this may be a performance issue and that it is advised to configure hikari with the autoCommit setting you use most often.

We can obviously do that in application code. But would it be wise for the doobie.hikari.HikariTransactor#newHikariTransactor constructor to include a call to setAutoCommit(false) given that doobie generally works that way?

I see some chatter in gitter about this over the years (https://gitter.im/tpolecat/doobie?at=58e3a907ad849bcf424e1fcd), so does seem to be a common source of confusion...

jyoo980 commented 4 years ago

I wouldn't mind taking this task on, if it's something the community decides on doing 🙂