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
 
Ross A. Baker  
View profile  
 More options Apr 27 2011, 1:33 pm
From: "Ross A. Baker" <ba...@alumni.indiana.edu>
Date: Wed, 27 Apr 2011 13:33:08 -0400
Local: Wed, Apr 27 2011 1:33 pm
Subject: Re: [scalatra-user] Re: MySQL connection pooling with C3P0
Handler is sort of an around filter, with pros (completely wraps
around ScalatraKernel, easier to reuse) and cons (more verbose).  But
around filters in the ScalatraKernel could be implemented as a
generalization of the existing before and after filters.

On Wed, Apr 27, 2011 at 11:26 AM, Wille Faler <wille.fa...@gmail.com> wrote:
> Does Scalatra have an equivalent of an "around"-filter?
> That could replace a lot of ugliness that comes with dealing with
> before/after/onRequest/etc lifecycle type events, as you can simply compose
> functions in different ways..

> On 27 April 2011 16:21, Ross A. Baker <ba...@alumni.indiana.edu> wrote:

>> I tend to prefer handlers to before/after filters, but it's not a
>> unanimous opinion.  Depends on the use case, I guess.

>> There's a GitHub wiki that has never gotten off the ground.
>> Documentation is in the README and being migrated to the in-progress
>> website project.  Pull requests for those are always appreciated.
>> With the right abstraction, I could also see that Handler evolving
>> into a scalatra-squeryl helper module.

>> On Wed, Apr 27, 2011 at 11:02 AM, Dustin Withers <fadedd...@gmail.com>
>> wrote:
>> > Wow, fantastic. Thanks for the help. I was just able to get the
>> > dynamic variable working, it seemed like I would use the value inside
>> > the block but I was confused. Your handler trait is quite superior. Is
>> > there a wiki that I can post all of this? Most of the google scouring
>> > I have done has not been this helpful and maybe having one place to
>> > show how to do a boring old MySQL connection could be helpful to
>> > others?

>> > On Apr 27, 9:46 am, "Ross A. Baker" <ba...@alumni.indiana.edu> wrote:
>> >> withValue one sets the value for the life of the block you pass it, so
>> >> dlSession would be null again after the before filter.  I think you
>> >> want:

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

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

>> >> Alternatively you could implement Handler:

>> >>    trait DlSessionSupport extends Handler {
>> >>      val dlSession = new DynamicVariable[Session](null)

>> >>      abstract override def handle(req: HttpServletRequest, resp:
>> >> HttpServletResponse) {
>> >>        dlSession.withValue(SessionFactory.newSession) {
>> >>          dlSession.value.bindToCurrentThread
>> >>          try {
>> >>            super.handle(request, response)
>> >>          } finally {
>> >>            dlSession.value.close
>> >>            dlSession.value.unbindFromCurrentThread
>> >>          }
>> >>        }
>> >>      }
>> >>    }

>> >>    class DailyLifFilter extends ScalatraFilter with ScalateSupport
>> >> with DlSessionSupport

>> >> On Wed, Apr 27, 2011 at 10:36 AM, 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

>> >> --
>> >> Ross A. Baker
>> >> ba...@alumni.indiana.edu
>> >> Indianapolis, IN, USA

>> --
>> Ross A. Baker
>> ba...@alumni.indiana.edu
>> Indianapolis, IN, USA

--
Ross A. Baker
ba...@alumni.indiana.edu
Indianapolis, IN, USA

 
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.