You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by Ramesh Venkitaswaran <ve...@gmail.com> on 2011/02/14 03:06:44 UTC

DIO and persistent connections

Hello
As I was looking through the dio*tcl code in general and
dio_Oracle.tcl, in particular, it seems like the code opens and closes
a database connection every time a "open" or "close" method is called.
(It calls  "oralogon" and a "oralogoff").  In oracle establishing a
connection is a fairly expensive process and I would like to re-use
connections as much as possible. Is there a setting where each child
process could re-use an already established connection? I'm sort of
thinking along the lines of mod_perl's Apache::DBI where calling a
disconnect() is turned into a no-op and a connect() figures out if
there's an existing connection and hands it off to the client.

[please Cc me, as I'm not subscribed to the list. Thank you]

--
rv

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: DIO and persistent connections

Posted by Massimo Manghi <ma...@unipr.it>.
On 02/14/2011 04:25 AM, Ramesh Venkitaswaran wrote:
> On Sun, Feb 13, 2011 at 8:23 PM, Damon Courtney<da...@tclhome.com>  wrote:
>> I usually would just create a single DIO object in the global namespace if it didn't already exist.  Something like:
>>
>> if {[info commands ::DIO] eq ""} {
>>     ## Create ::DIO object
>> }
>>
>> I did that as part of the initialization of my code.  Since the created connection exists in the global namespace, it doesn't get deleted when the ::request namespace is destroyed, so it sticks around between invocations.
>
> Ah, that's a good tip. Could the open connection be source in as a
> part  the ChildInitScript directive and the close connection would be
> in the ChildExitScript directive?
>

Yes, Child[Init|Exit]Script directive are there for this purpose too. 
They run one at global level upon child creation, therefore everything 
they create outside ::request is persistent across http requests, though 
you don't necessarily have to store persistent data in the global (::) 
namespace. Every user defined namespace that stems from :: is preserved, 
only ::request (and descendants) is wiped out.

> One additional question though. What's the standard Rivet way to
> 'ping' the database before using the connection? I'm looking for
> something similar to the Apache:DBI's ping() method.
>

This is an interesting question. I leave a definite answer to Damon, but 
I don't think DIO provides an interface method for this functionality. 
Working with Mysql I solved the problem introducing a hack in a 
'BeforeScript'. Probably not the best way to get it done.

  -- Massimo

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: DIO and persistent connections

Posted by Ramesh Venkitaswaran <ve...@gmail.com>.
On Sun, Feb 13, 2011 at 8:23 PM, Damon Courtney <da...@tclhome.com> wrote:
> I usually would just create a single DIO object in the global namespace if it didn't already exist.  Something like:
>
> if {[info commands ::DIO] eq ""} {
>    ## Create ::DIO object
> }
>
> I did that as part of the initialization of my code.  Since the created connection exists in the global namespace, it doesn't get deleted when the ::request namespace is destroyed, so it sticks around between invocations.

Ah, that's a good tip. Could the open connection be source in as a
part  the ChildInitScript directive and the close connection would be
in the ChildExitScript directive?

One additional question though. What's the standard Rivet way to
'ping' the database before using the connection? I'm looking for
something similar to the Apache:DBI's ping() method.

Thanks
--
rv

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: DIO and persistent connections

Posted by Damon Courtney <da...@tclhome.com>.
I usually would just create a single DIO object in the global namespace if it didn't already exist.  Something like:

if {[info commands ::DIO] eq ""} {
    ## Create ::DIO object
}

I did that as part of the initialization of my code.  Since the created connection exists in the global namespace, it doesn't get deleted when the ::request namespace is destroyed, so it sticks around between invocations.

Damon


On Feb 13, 2011, at 8:06 PM, Ramesh Venkitaswaran wrote:

> Hello
> As I was looking through the dio*tcl code in general and
> dio_Oracle.tcl, in particular, it seems like the code opens and closes
> a database connection every time a "open" or "close" method is called.
> (It calls  "oralogon" and a "oralogoff").  In oracle establishing a
> connection is a fairly expensive process and I would like to re-use
> connections as much as possible. Is there a setting where each child
> process could re-use an already established connection? I'm sort of
> thinking along the lines of mod_perl's Apache::DBI where calling a
> disconnect() is turned into a no-op and a connect() figures out if
> there's an existing connection and hands it off to the client.
> 
> [please Cc me, as I'm not subscribed to the list. Thank you]
> 
> --
> rv
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
> For additional commands, e-mail: rivet-dev-help@tcl.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org