[dev] Database access in process fork (Jan Schneider)

Ralf Lang lang at b1-systems.de
Wed Aug 29 19:18:04 UTC 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 29.08.2012 21:15, schrieb Ian Roth:
> 
>> Zitat von Ian Roth <iron_hat at hotmail.com>:
>> 
>>> I have a cron script that takes requests from a queue and
>>> makes calls to cloud service based on those queued requests.
>>> These API calls can take a long time to receive a response, and
>>> under heavy load it would be nice to be able to use one process
>>> per request. The trouble I am having is that using pcntl_fork()
>>> causes child processes to use the same Horde_Db instance as the
>>> parent, and this causes exceptions when multiple child
>>> processes attempt to write a response back to the database.
>>> What is the best approach: creating a new Horde_Db instance in
>>> each child process, or using?semaphore?between child processes
>>> to avoid resource deadlock? Here is the code I have so far, and
>>> it can be modified at this 
>>> url:?https://gist.github.com/3154317
>> 
>> You could either use a separate Horde_Db instance for each
>> process or use some locking mechanism to avoid concurrent access.
>> The choice probably depends on whether you need to scale this
>> application with time constraints or resource constraints.
> 
> I think I will treat this problem as time constrained. How do I
> force the driver factory to give a new instance each time it is
> requested? I based the code after the SQL driver code found in the
> skeleton application.

Most factories I've seen in horde code cache by $name, so if you have
a random $name key, you probably get a new factory each time.


- -- 
Ralf Lang
Linux Consultant / Developer
Tel.: +49-170-6381563
Mail: lang at b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlA+auwACgkQCs1dsHJ/X7BRxQCg9k9iDL20Cv56ByMedJ7PB9Za
d1UAni7fsrCLLFMupMpfllQpB8YNrfA0
=f+8n
-----END PGP SIGNATURE-----


More information about the dev mailing list