Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Sharing a database handle over multiple processes

by pope (Friar)
on Jun 28, 2001 at 09:00 UTC ( #92213=note: print w/replies, xml ) Need Help??

in reply to Sharing a database handle over multiple processes

A DBI database handle does survive across fork().
But the problem here is, when a child exits, the database handle gets disconnected, and since the same database connection is shared among the other children, this will affect them as well.

If the overhead of connect() is really the bottleneck of your system, then I'd suggest you to follow the apache/mod_perl model:
a child doesn't exit immediately after serving a client, but doing an accept() loop instead to serve more subsequent requests until a certain maximum number reached.
Your program still creates a new $dbh for each forked child, but this $dbh is reused several times within the child before exits, not just once. This way you reduce the number of connect().

Update: Added a suggestion.

  • Comment on Re: Sharing a database handle over multiple processes

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2020-01-17 19:07 GMT
Find Nodes?
    Voting Booth?