Hi, monks!
I've got a server which listen()s on a certain port and
then fork()s off a new process for every accept()ed
connection.
Each child process then reads X number of bytes from the
socket, checks data for validity and then writes everything
to the database (Oracle).
In the current implementation, each child process does its
own $dbh = DBI->connect($source, $uname, $auth, \%attr);
thing and I have a feeling that this slows things down
dramatically...
So, my question is:
Is there a way to share the same database connection
among multiple processes ?
For instance, can I do the following?
...
my $dbh = DBI->connect($source, $uname, $auth, \%attr);
while(1){
##########################
# accept() code goes here
##########################
my $cid = fork();
if (defined $cid){
if ($cid == 0){
my $statement = q!a SQL statement goes here!;
my $sth = $dbh->prepare($statement);
$rv = $sth->execute;
... etc ...
exit 0;
}
}else{
# handle the error
}
...
What will happen in case when multiple processes try to
use their copies of $dbh at the same time?
Any input is greately appreciated.
Thanks in advance!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.