Connection Pooling – Best Library Choice for VM Deploys

connection-pooling

HickariCP docs say:

HikariCP relies heavily on accurate high-resolution timers for both
performance and reliability. It is imperative that your server is
synchronized with a time-source such as an NTP server. Especially if
your server is running within a virtual machine. Do not rely on
hypervisor settings to "synchronize" the clock of the virtual machine.
Configure time-source synchronization inside the virtual machine. If
you come asking for support on an issue that turns out to be caused by
lack time synchronization, you will be taunted publicly on Twitter.

Which other connection pooling libraries would you choose, which are less sensitive to virtual machine time drifts?

Best Answer

Any pool in an environment in which time can flow backwards or leap forwards, which it can in a virtual machine, is going to be subject to spurious failure when it does so.

Moreover, it is not just connection pools that are affected.

Any...

  • Timed waits
  • Timed polls from a concurrent collection
  • Object.wait() with a timeout
  • Thread.sleep() call
  • ...
  • Anything in Java that requires the measurment of time is affected.

If you cannot nail down your clock drift, you will encounter unexplained application failures, occurring in your code and third-party libraries.

HikariCP (i.e.me) got sick of spending hours trouble-shooting a user's issue, reading logs and thread dumps, only to discover their clock had jumped backwards or forwards more than a minute.

User: "Why did I get a bunch of connection timeouts?!"

(several days of back-and-forth questions and examining logs later...)

HikariCP: "Well, you asked the pool to try for 30 seconds to give you a connection ... then your clock jumped forward 42 seconds and Java (and the OS) unparked all the threads as if time had really passed."

It is really simple to fix, just configure NTP inside your VM.