Search code examples
javatomcatc3p0

Running out of c3p0 pooled connections lead to high CPU?


I'm pretty sure I'm leaking connections over time, leading to the Tomcat process (Windows) locking up.

Symptoms when in a locked-up state:

  • High CPU (pegged at 50%+)
  • Large number of database TCP connections
  • Most/all apr threads stuck in c3p0...getConnection...awaitAvailable

If the theory is correct and we're leaking connections, and eventually running out of them, could this lead to high CPU usage?

I've noticed the busy threads are actually mostly GC.


Solution

  • It's not obvious why a Connection leak would lead to high CPU usage, unless you have a very large maxPoolSize and there is some overhead to the outstanding Connections.

    Regardless, the thing to do is to fix your Connection leak. See e.g. C3P0 Spring Hibernate: Pool maxed out. How to debug?

    If there is still a CPU issue once the Connection leak is resolved, well, then you'll have less confusion and noise to deal with tracking down the issue. But the Connection leak may well be the issue, somehow.