On Monday, January 03, 2011 22:48:53 Jeff Anderson wrote: > I am looking to set up a mod_perl handler which keep track of the > count of requests coming in. Each child process will store this data > in local memory and after 5-10 minutes have passed, each child process > will merge its data into a central database, the goal being that each > child will not have to hit a database for every request. > > I have a handler that contains a data in $self for each child and when > a REQUEST comes through, a check is made to see if the interval has > passed and if so, the child will merge its data with the database. > > The problem is --- how do i additionally have each child merge its > data on a schedule -- that is, without relying only on an incoming > request to "hit" that specific child process? I have tried 2 attempted > solutions with no luck. (Keep in mind that as long as requests are > coming in, the children will eventually merge their data within a good > degree of accuracy, but only if requests are coming in.) > > Attempt #1 --- configure a signal handler and send a signal to each > child process - this didn't seem to work but i am about to try some > more tests. I have read in the docs, however, that sending direct > signals to mod_perl children is not recommended. > > Attempt #2 --- register a Clean Up hook. This doesn't seem to work for > me because, as i understand so far, assigning a reference to a sub via > PerlCleanupHandler is not the same as calling the object's method. > Hence ... i do not have access to $self nor the local memory. So, the > sub is called via the Clean Up phase, but the sub is meant to be > called as a method (and i can't use $self has a hash ref unless called > as a method). > > Other considerations: > > - Perhaps each child process will need to use it's own SQLite or similar > cache? - Perhaps there is another hook that i do not know about that > better suits such needs? > - Perhaps my mistake is obvious -- configuring Clean up hook incorrectly, > etc. > > Any information will be greatly appreciated. I hope everyone had a > Happy New Year. On a side note -- there is a storage facility in LA > called "Dollar Self Storage" ... :)
I can think of 2 solutions. 1) perhaps the Apache scoreboard already has all the information you need. Then you don't need any special hook. Just configure a scroreboard file on disk. I do that normally on a tmpfs fileysystem (Linux). So it does really exist only in RAM. Then write an external daemon that uses Apache2::ScorebordFile to read the information on a regular basis. 2) quite similar. But if the required information is not available in the scoreboard you can establish your own using either File::Map or IPC::ScoreBoard. In both cases you have to deal with the fact that Apache starts up additional children on demand and also terminates them when the load goes down. The apache scoreboard does contain the necessary information to do that. Torsten Förtsch -- Need professional modperl support? Hire me! (http://foertsch.name) Like fantasy? http://kabatinte.net