Sharing connection across forked processes

[prev] [thread] [next] [Date index for 2004/12/20]

From: Alexander Christian Westholm
Subject: Sharing connection across forked processes
Date: 15:55 on 20 Dec 2004
--Apple-Mail-4-696881235
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed

All,

	I posted a few weeks ago about writing a threaded webapp that uses  
CDBI. The final solution seems to be writing the logic as a daemon that  
will provide results for the UI. The daemon will spawn either a  
thread(which I'd prefer), or a process for each task it needs to do.  
These tasks all have need of database connections. However, when using  
CDBI, I get errors similar to the following:

Broadband::DBI::Carrier can't SELECT car_id
FROM   Carrier
WHERE  company = ?
: DBD::mysql::st execute failed: Lost connection to MySQL server during  
query [for Statement "SELECT car_id
FROM   Carrier
WHERE  company = ?
"] at /Library/Perl/5.8.1/DBIx/ContextualFetch.pm line 51.
  at  
/Library/Perl/5.8.1/darwin-thread-multi-2level/Broadband/QualQuery/ 
Base.pm line 38

	I assume I need to create the database handle myself per process,  
instead of allowing Ima::DBI to do the work... the docs are not  
terribly helpful on this matter: they make reference to writing my own  
db_Main method, but provide no example. Could someone illustrate this?  
Also, assuming I go that route, will CDBI itself use the db_Main method  
to generate its connections, or will it simply be a method that I'll  
call to get a connection outside of Ima::DBI's cache? I guess any  
clarification about db_Main would be appreciated.

	Notably, the code dies with an error related to sharing database  
handles across threads when trying to execute under ithreads instead of  
forked processes. Any help appreciated.

	-- Alex
--Apple-Mail-4-696881235
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII

All,


	I posted a few weeks ago about writing a threaded webapp that uses
CDBI. The final solution seems to be writing the logic as a daemon
that will provide results for the UI. The daemon will spawn either a
thread(which I'd prefer), or a process for each task it needs to do.
These tasks all have need of database connections. However, when using
CDBI, I get errors similar to the following:


<fixed><color><param>FFFE,0000,0000</param><x-tad-bigger>Broadband::DBI::Carrier
can't SELECT car_id</x-tad-bigger></color><x-tad-bigger>

</x-tad-bigger><color><param>FFFE,0000,0000</param><x-tad-bigger>FROM  
Carrier</x-tad-bigger></color><x-tad-bigger>

</x-tad-bigger><color><param>FFFE,0000,0000</param><x-tad-bigger>WHERE 
company = ?</x-tad-bigger></color><x-tad-bigger>

</x-tad-bigger><color><param>FFFE,0000,0000</param><x-tad-bigger>:
DBD::mysql::st execute failed: Lost connection to MySQL server during
query [for Statement "SELECT car_id</x-tad-bigger></color><x-tad-bigger>

</x-tad-bigger><color><param>FFFE,0000,0000</param><x-tad-bigger>FROM  
Carrier</x-tad-bigger></color><x-tad-bigger>

</x-tad-bigger><color><param>FFFE,0000,0000</param><x-tad-bigger>WHERE 
company = ?</x-tad-bigger></color><x-tad-bigger>

</x-tad-bigger><color><param>FFFE,0000,0000</param><x-tad-bigger>"] at
/Library/Perl/5.8.1/DBIx/ContextualFetch.pm line 51.</x-tad-bigger></color><x-tad-bigger>

</x-tad-bigger><color><param>FFFE,0000,0000</param><x-tad-bigger> at
/Library/Perl/5.8.1/darwin-thread-multi-2level/Broadband/QualQuery/Base.pm
line 38


</x-tad-bigger></color></fixed>	I assume I need to create the database
handle myself per process, instead of allowing Ima::DBI to do the
work... the docs are not terribly helpful on this matter: they make
reference to writing my own db_Main method, but provide no example.
Could someone illustrate this? Also, assuming I go that route, will
CDBI itself use the db_Main method to generate its connections, or
will it simply be a method that I'll call to get a connection outside
of Ima::DBI's cache? I guess any clarification about db_Main would be
appreciated.


	Notably, the code dies with an error related to sharing database
handles across threads when trying to execute under ithreads instead
of forked processes. Any help appreciated.


	-- Alex
--Apple-Mail-4-696881235--

Sharing connection across forked processes
Alexander Christian Westholm 15:55 on 20 Dec 2004

Re: Sharing connection across forked processes
Perrin Harkins 18:30 on 22 Dec 2004

Generated at 12:15 on 16 Jan 2005 by mariachi v0.52