bugsbunny has asked for the wisdom of the Perl Monks concerning the following question:

hi,
How u do syncronization between different processes ?
I'm thinking of implementing one management script which will launch different scripts depending on some conditions.
The management script can run as daemon or fire-up from time to time..
let me give one example, i call :
mgmt -addUser blah
and it fires :
1. A script which adds a user to DB
2. generate modified dhcpd.conf file
3. copy the file to other computer
4. restart the remote dhcpd server


several problems arise here, I dont want to call this sequence too fast so that it can DoS the dhcp-service. (think of many users calling "mgmt" simultaneously)
On the other hand "mgmt" may run in deamon mode and accept queries for executing many similar sequences, so it would be better if I wait ~5sec or so before restarting the service.
Some of the functions such as adding user can be implemented as part of "mgmt" or as separate process, what I have in mind is that no matter that some part of the process is a part of "monilite" program it still has to syncronize with the others..
I also want to be a little clever say i got for 10 times every 5 sec request for restart, it will be better then to increase this 5sec period to say 15sec..(up to X) and later when things go down fall to 5sec again.
This is simplification of cource there will be a doesen of processes that copy files between machines, alot of services involved etc...
I just need some pointers for further reading ofcource Perl oriented :"), discussion etc..

Replies are listed 'Best First'.
Re: process syncronization
by Corion (Patriarch) on Oct 06, 2003 at 07:33 UTC

    As you already have a database, I would use several tables in that database to model the whole process:

    1. Submissions of new users go into the table new_users
    2. A script is triggered by cron every n minutes and checks whether there are entries in the table new_users. If so, it modifies the main users table according to the actions in new_users (insert,update,delete) and it also generates an generates an entry with the timestamp and ("regenerate","dhcpd.conf",Null) in the table jobs.
    3. Another script is triggered by cron every minute and checks whether there is a row dhcpd.conf,Null in jobs. If so, it regenerates dhcpd.conf and updates that row to "regenerate",dhcpd.conf,timestamp, and generates a new row in that table, "transfer","dhcpd.conf",Null
    4. Another script is also called by cron every minute that checks whether a transfer row is available in the database. It then executes the submitted transfer and updates the row.

    This method has a latency of at least 1 minute per step involved, which should be small enough for adding new clients to dhcp, but which might not be enough for other tasks. There you could increase the polling frequency, but a hardcoded synchronized sequence via a shell script would most likely be better (combining all steps after the initial submission into one shell script).

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
•Re: process syncronization
by merlyn (Sage) on Oct 06, 2003 at 07:26 UTC