Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Using fork with DBI to create simultaneous db connections.

by htoug (Deacon)
on Feb 08, 2005 at 11:20 UTC ( #429015=note: print w/ replies, xml ) Need Help??


in reply to Using fork with DBI to create simultaneous db connections.

Each child must have its own connection to the database as the DBD (and possibly the database system) stores data in process-local storage. The poor database system will be very confused when it get requests from different processes in the same connection - each having possibly a different view of the state of the connection. The results are highly unpredictable, time and usage dependent and will cause your hair to fall out and your teeth to rot.

Either let each child have its own connection, or have a common process (eg the 'mother') handle all the database traffic, and use something else to communicate with this 'db-server-process', some sort of RPC or shared memory or... YMMV.

Just don't (repeat DON'T) share database connections between processes.

Did I remember to say that you should not share connections between processes?


Comment on Re: Using fork with DBI to create simultaneous db connections.
Re^2: Using fork with DBI to create simultaneous db connections.
by guice (Scribe) on Mar 23, 2005 at 14:55 UTC

    Either let each child have its own connection, or have a common process (eg the 'mother') handle all the database traffic, and use something else to communicate with this 'db-server-process', some sort of RPC or shared memory or... YMMV.

    Okay, I'm having the same error and I'm getting the same with every other thread after the first thread finishes. Any thoughts? I'm doing just that myself; Global dbh in $this->{'dbh'} and each child defines it's own $this->{'_dbh-child'}. As soon as I call the first $this->{'_dbh-child'}->disconnect(), every other disconnect fails or spews out that error above, including the master {'dbh'}.

    -- philip
    We put the 'K' in kwality!

      The above can be omitted. Turns out the children where closing out the Global DBI object every time they where closing themselves out. It was causing the error. Moving the Global DBI call to a localized method fixed it right up.

      -- philip
      We put the 'K' in kwality!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://429015]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-12-26 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls