[Catalyst] How to share a database connection across multiple Catalyst apps?

Javier Arturo Rodriguez javier at rodriguez.org.mx
Wed Sep 8 18:17:46 GMT 2010


  On 9/8/10 4:54 PM, Simon Miner wrote:
> Thanks for the responses,
>
> Jason, I don't think reducing the number of database connections will =

> hurt responsiveness.  Even though there are 3 separate Catalyst apps, =

> each HTTP request will only involve one of them (since they all run =

> out of the same web server), so there should never be contention =

> between the apps for the shared database connection.  Does this make =

> sense?
>
> Tom and Nicholas, I wish this was premature optimization, but my =

> organization has experienced serious performance issues in the past =

> related to multiple (Oracle) database connections per HTTP server =

> process.  Extra Oracle connections are expensive to maintain, =

> particularly on the database server, and so we've tried to ensure that =

> a single server process only has a single connection to a given =

> database (since that's all it should need at any given time).
>
> I've attached a Devel::NYTProf screenshot for one of the server =

> processes I profiled this morning. Looks like it confirms the multiple =

> database connections.
>
> So back to initial question -- How do I update the models of my three =

> Catalyst apps to share a single Oracle database connection?
Sounds like a job for Apache::DBI -- it will cache one connection per =

process and hand it over to the next app that requests it as long as =

it's valid -- but keep in mind that the connection attributes MUST be =

the same for all three Catalyst apps for the magic to happen. From the =

perldoc:

> The parameters defining the connection have to be exactly the same, =

> including the connect attributes! If there is no appropriate database =

> handle or if the ping method fails, a new connection is established =

> and the handle is stored for later re-use.
I agree that this is not early optimization -- just good housekeeping. =

Oracle SQL Net connections are indeed expensive to set up but tend to =

consume near-zero resources when idle, so I would not worry too much =

about connection reuse among apps just yet - in my book this is more of =

a sysadmin issue.

>
> Thanks again.  I really appreciate your feedback.
>
>  Simon
Hope this helps,

-Javier Arturo Rodriguez

>
> On Tue, Sep 7, 2010 at 11:40 PM, Nicholas Wehr =

> <catalyst at bionikchickens.com <mailto:catalyst at bionikchickens.com>> wrote:
>
>     I'm with Tom on this one. Unless you've narrowed all optimization
>     efforts and this is all you have left - it could be worth a try..
>     but as Jason points out, you may not gain a thing. I'd recommend
>     profiling your code and tracking down performance issues from that
>     base level. Please post your results - I've very curious!
>
>     -nw
>
>
>     On Tue, Sep 7, 2010 at 7:21 PM, Tomas Doran <bobtfish at bobtfish.net
>     <mailto:bobtfish at bobtfish.net>> wrote:
>
>
>         On 7 Sep 2010, at 18:59, Simon Miner wrote:
>
>             All three of these apps run under a single Apache
>             1.3.42/mod_perl 1.31 server.
>
>
>         Wow, mod_perl 1.... Ok then :)
>
>
>              It appears that each server process creates a unique
>             database connection variable for each of these apps.
>             Although these database connections get reused from
>             request to request, I would like to make things even more
>             efficient by having a single database connection variable
>             per server process which gets shared across all 3 Catalyst
>             apps.
>
>
>         Why do you think that this will help or affect anything?
>
>         I.e. is this not premature optimisation?
>
>         Cheers
>         t0m
>
>
>
>         _______________________________________________
>         List: Catalyst at lists.scsys.co.uk
>         <mailto:Catalyst at lists.scsys.co.uk>
>         Listinfo:
>         http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>         Searchable archive:
>         http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>         Dev site: http://dev.catalyst.perl.org/
>
>
>
>     _______________________________________________
>     List: Catalyst at lists.scsys.co.uk <mailto:Catalyst at lists.scsys.co.uk>
>     Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>     Searchable archive:
>     http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>     Dev site: http://dev.catalyst.perl.org/
>
>
>
>
> -- =

> -- Simon
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.u=
k/
> Dev site: http://dev.catalyst.perl.org/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100908/e6df4=
bc8/attachment.htm


More information about the Catalyst mailing list