Re: Sharing a DBI::Mysql database connection with your children
- From: "Peter J. Holzer" <hjp-usenet2@xxxxxx>
- Date: Mon, 31 Mar 2008 10:57:56 +0200
On 2008-03-31 03:45, Andrew DeFaria <Andrew@xxxxxxxxxxx> 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
Do you want to use threads or fork?
would make the process faster because I wouldn't need to open the
database every time a new client wanted service.
This cannot be done. Not only will the database server get a mixture of
requests from different database clients on the same connection (this
could be solved), but it also has to send back all replies via the same
connection: Which client will receive the response? There is no way to
determine that.
(There is at least one RDBMS where the client automatically opens a new
connection when it detects a pid change - presumably the new connection
will be pre-authenticated and faster to establish).
Your best bet is probably to use a pre-forked approach like some web
servers. Run a number of your your daemons in parallel, all listening on
the same port. A client connecting to that port will get any of them.
If all are busy, the client has to wait, or a controlling process can
start more worker processes.
hp
.
- Prev by Date: Re: printf: zero pad after the decimal a given amount
- Next by Date: Re: NIC Configurations
- Previous by thread: FAQ 8.5 How do I read just one key without waiting for a return key?
- Next by thread: Re: Sharing a DBI::Mysql database connection with your children
- Index(es):
Relevant Pages
|