Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion MySQL connection pooling with C3P0
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David McLaughlin  
View profile  
 More options May 1 2011, 12:03 pm
From: David McLaughlin <mesave...@gmail.com>
Date: Sun, 1 May 2011 09:03:09 -0700 (PDT)
Local: Sun, May 1 2011 12:03 pm
Subject: Re: MySQL connection pooling with C3P0
Hi Dustin,

The problem here is that you are not wrapping your Squeryl statements
in transactions. If you look at the Query class in Squeryl dsl package
you'll find you are duplicating code from there in your Scalatra
traits almost verbatim:

https://github.com/max-l/Squeryl/blob/master/src/main/scala/org/squer...

So all you really need to do in your intitialize method is set up the
c3p0 connection pool and Squeryl ConcreteFactory, then inside your
Scalatra views just wrap any database code with transaction or
inTransaction as described here:

http://squeryl.org/sessions-and-tx.html

Using the transaction abstraction also has the benefit of not having
every handler reserving a connection from your pool, regardless of
whether or not it actually needs it. In addition, I'm fairly sure that
if someone was to use transaction within your code, they would get a
NullPointerException since Squeryl will unbind the session before you
try to close and unbind it in your finalizer.

Cheers,
David

On Apr 27, 4:36 pm, Dustin Withers <fadedd...@gmail.com> wrote:

> Where should I bind that variable? In a companion object to the
> Filter? Or should I still do it in my Filters class? Like:
> class DailyLifFilter extends ScalatraFilter with ScalateSupport with
> DatabaseInit {
>   val dlSession = new DynamicVariable[Session](null)

>   before {
>     dlSession.withValue(SessionFactory.newSession) {
>       dlSession.value.bindToCurrentThread
>     }
>   }

>   after {
>     dlSession.value.close
>     dlSession.value.unbindFromCurrentThread
>   }

> }

> On Apr 27, 9:12 am, Wille Faler <wille.fa...@gmail.com> wrote:

> > Hmm, making it an instance variable of your filter is not thread-safe, so
> > you should probably bind your session to a DynamicVariable/ThreadLocal
> > (DynamicVariable is Scala's equivalent of ThreadLocal)..

> > On 27 April 2011 15:10, Dustin Withers <fadedd...@gmail.com> wrote:

> > > Should something like the following work?

> > > class DailyLifFilter extends ScalatraFilter with ScalateSupport {
> > >  var dlSession:Session = null

> > >  before {
> > >    dlSession = SessionFactory.newSession
> > >    dlSession.bindToCurrentThread
> > >  }

> > >  after {
> > >    dlSession.close
> > >    dlSession.unbindFromCurrentThread
> > >  }
> > > ....

> > > Thanks,
> > > -dustin

> > > On Apr 27, 9:01 am, Wille Faler <wille.fa...@gmail.com> wrote:
> > > > You're probably leaking sessions and connections, as you are not closing
> > > > them or unbinding the session after a request:

> > > > session.close
> > > > session.unbindFromCurrentThread

> > > > On 27 April 2011 14:37, Dustin Withers <fadedd...@gmail.com> wrote:

> > > > > Hello all,

> > > > > I'm new to Scala and new to Scalatra, heck I'm kinda new to Java web
> > > > > development other than a bunch of Oracle work in another life. Anyhow,
> > > > > I'm having some trouble with MySQL and C3P0 connection pooling . The
> > > > > code can be seen here:
> > > > >https://gist.github.com/944244

> > > > > Originally I wasn't using any kind of connection pooling and I
> > > > > eventually exhausted my connections. Now instead of exhausting
> > > > > connections the app seems to run out of C3P0 connections and then
> > > > > locks up with no logging in the console and no CPU usage but the
> > > > > thread count goes up each time I request a page.

> > > > > I've played with all of C3P0's settings and I can stave off the
> > > > > failure by increasing MaxPoolSize but eventually after a enough page
> > > > > requests the app hangs.

> > > > > Any thoughts? Should I bother the people on the Squeryl mailing list?

> > > > > Thanks much for your time,
> > > > > -dustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.