Click here to get back home

Re: Sharing a DBI::Mysql database connection with your children

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Re: Sharing a DBI::Mysql database connection with your children xhoster 03-31-2008
Posted by xhoster on March 31, 2008, 1:06 pm
Please log in for more thread options
>
> I have a process I was thinking of making into a multithreaded daemon
> that deals with a MySQL database. The thought is that the daemon would
> open the database once, then listen for clients. As clients connected
> the daemon would fork off a copy of itself and handle the requests. This
> would make the process faster because I wouldn't need to open the
> database every time a new client wanted service.

On my system it takes less than one millisecond to open a connection
to a MySQL server (located on a different system.) Do you find that
connection time problematic? This is about the same amount of time
it takes to fork in the first place.


> However, I've found that once I fork the database handle (obtained
> through DBI) is no longer valid. Reading around a little bit I noticed
> people saying to reopen or reconnect to the database in the child.

Yes, true.

> Well
> that's the very time consuming thing

I find that hard to believe.

> I was trying to avoid!
>
> Does anybody know how to open a MySQL database such that that database
> connection can be used in forked children?

I don't. I rather doubt other people do, either. Maybe your server
should handle requests internally rather than forking.


Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Posted by szr on March 31, 2008, 2:22 pm
Please log in for more thread options
xhoster@gmail.com wrote:
>>
>> I have a process I was thinking of making into a multithreaded daemon
>> that deals with a MySQL database. The thought is that the daemon
>> would open the database once, then listen for clients. As clients
>> connected the daemon would fork off a copy of itself and handle the
>> requests. This would make the process faster because I wouldn't need
>> to open the database every time a new client wanted service.
>
> On my system it takes less than one millisecond to open a connection
> to a MySQL server (located on a different system.) Do you find that
> connection time problematic? This is about the same amount of time
> it takes to fork in the first place.

Normally this would be true, if the MySQL server is on the same network,
but if it's not, connection time depends entirely on the latency between
the OP's running system and the MySQL server, such is the case if it is
across the internet; it will surely take longer than a millisecond. But
then again, that would hardly be an ideal setup, but it's not unheard
of.

--
szr



Posted by A. Sinan Unur on April 1, 2008, 8:46 am
Please log in for more thread options

> I'm sorry. I didn't officially measure it. I remember another DBMS
> being extremely slow so I assume it. Will you ever forgive me?
> --
> Andrew DeFaria <http://defaria.com>
> Disk Full - Press F1 to belch.
>
> Attachment decoded: untitled-2.txt
> --------------060102070906040004010008
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>

I may consider it if you stop posting HTML attachments.

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by Tad J McClellan on April 1, 2008, 7:01 pm
Please log in for more thread options
>
>> I'm sorry. I didn't officially measure it. I remember another DBMS
>> being extremely slow so I assume it. Will you ever forgive me?
>> --
>> Andrew DeFaria <http://defaria.com>
>> Disk Full - Press F1 to belch.
>>
>> Attachment decoded: untitled-2.txt
>> --------------060102070906040004010008
>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> <html>
>> <head>
>
> I may consider it if you stop posting HTML attachments.


Please don't tell him how to post.

http://groups.google.com/group/comp.lang.perl.misc/msg/1a331dca40c4d90a


Nobody else here ignores that netiquette, simply spend your
time answering their questions instead.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Similar ThreadsPosted
Re: Sharing a DBI::Mysql database connection with your children March 31, 2008, 4:57 am
Re: Sharing a DBI::Mysql database connection with your children March 31, 2008, 2:08 pm
Database Connection Problem June 23, 2006, 5:29 am
mysql connection failing as CGI November 21, 2006, 1:03 pm
Mod_perl: can I share a database connection by putting it in thestartup-script? February 13, 2005, 4:14 pm
How to set DBI connection timeout for Win32 Perl->MySQL ? October 13, 2007, 11:44 am
create connection from html form into insert MySQL data script September 8, 2004, 2:58 am
copy mysql database with perl December 22, 2004, 9:36 pm
compare two MySQL database structures April 5, 2006, 3:46 pm
Is there a wholly Perl Database equivalent to say MySQL? October 28, 2004, 11:40 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap