Do I need to use the C3P0 pool library in my (grails) web application?

I'm not familiar with the pooling library at all. I just discovered it via this blog post ) and I'm not sure if I should be using it in my grails / hibernate / MySQL based web application.

So my question is simple: in what situations would you suggest integrating a pooling library into a grails application? Always, Never, or just over the threshold of some connections?

PS: If you have ever used C3P0 in your web application, I am very grateful for your opinion (in terms of visible positive effects).

+2


a source to share


4 answers


Regardless of the federation implementation, you should always use connection pooling in your web application. Opening a database connection is a very expensive task, and the ability to reuse an existing and unoccupied connection greatly improves the performance of your site.



The connection can be managed by an application server (Tomcat, JBoss, Glassfish ...) or your application. The latter is easier to configure, but difficult to configure for deployment. Configuring a connection pool in your application and configuring your site to use it makes it easy to configure connection pool settings like minimum connections to keep, maximum downtime, etc.

+1


a source


My experience with this is pretty limited, but I ended up using C3P0 for the simple reason that Hibernate doesn't seem to support MySQL reloads. I was getting "Broken pipe" every morning because our hosting service was restarting MySQL every night.



I searched for it and the only advice I could find was to use ... connection pooling on the application server or C3P0. For me, the latter works great.

+1


a source


I always use connection pooling for two reasons:

  • Because opening connections is a costly operation.
  • It's dead - just set to work transparently, so there is no real advantage to not using it.

If you are already using hibernate, just change your hibernate.cfg.xml connection.provider_class to use org.hibernate.connection.C3P0ConnectionProvider and dump the c3p0 jar file into the WEB-INF / lib servlet folder. Done.

If you are using JNDI and GlobalNamingResources declaration, change the type property to point to com.mchange.v2.c3p0.ComboPooledDataSource and throw jar c3p0 into Tomcat / lib folder. Done.

+1


a source


C3P0 is a very decent pool, but I would still recommend using your application server or servlet's connection pool and configuring Grails to use it through a regular DataSource. Use an offline connection pool when you can't (in which case C3P0 is a good choice).

0


a source







All Articles