SPUG: Perl Question?

jerry gay jerry.gay at gmail.com
Wed May 4 10:50:00 PDT 2005


you might instead consider one of my favorite locking hacks:

  #!/usr/bin/perl
  ...
  ## ensure only one instance of this script is running
  INIT { flock DATA => LOCK_EX | LOCK_NB or exit 1 }
  ...<script body here>...
  __DATA__

which will exit if the script can't get an exclusive lock on itself.
no messy lockfiles to worry about.
~jerry

On 5/4/05, dleonard at dleonard.net <dleonard at dleonard.net> wrote:
> As someone who has been rewriting code that uses lockfiles to determine whether it should launch I have to say this it definitely not an optimal way of doing things.  If a mount becomes unavailable, the filesystem becomes read-only, or a user or other process modifies the filesystem, this design breaks down.
> 
> I would recommend instead querying the process table for other processes running as $0.
> 
> --
> 
> <Douglas Leonard>
> <dleonard at dleonard.net>
> <Perfection should always be the goal.  Settling for excellence is
> sometimes acceptable.>
> 
> On Tue, 3 May 2005, Rick Croote wrote:
> 
> > I agree with Aaron response, but I would make a very simple statement and
> > solution.  Repeatedly running things at 15 minute intervals, when that may
> > extend past 15 minutes just isn't a good idea.  Simply modify the batch
> > file with a simple locking mechanism that says if a flagfile exist, do not
> > start, and if it doesn't exist, create the flagfile and continue with your
> > process, and finally remove the flagfile at the end.  In this way you will
> > never fall into at least the quicksand, I'm sure others are waiting
> > though.  This will automatically push emailed reports to be every 30
> > minutes, or longer, if the 15 minute interval is too short.  Then, if you
> > are not getting your reports often enough, you can then at least look into
> > why that is, but at least your 15 minute cycle will not be part of the
> > problem.
> >
> > ---
> > Rick Croote
> > Software Engineer
> > Environment and Tools Team
> > Philips Medical Systems
> > Bothell, WA
> > Rick.Croote at Philips.com
> > Phone: 425-487-7834
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Mike Alba <michaelpalba at yahoo.com>
> > Sent by:
> > spug-list-bounces at pm.org
> > 05/03/2005 03:27 PM
> >
> >         To:     spug-list at pm.org
> >         cc:     (bcc: Rick Croote/ATL-BTL/MS/PHILIPS)
> >         Subject:        SPUG: Perl Question?
> >         Classification:
> >
> >
> >
> >
> > Hi,
> >
> >   I have a question regarding perl performance.
> > I have batch file that executes the same perl
> > program a few times but with different parameters.
> > In other words there are different operations
> > being performed, sql reports are generated from
> > the database, files are moved around, files are
> > emailled, etc. This batch runs every 15 minutes
> > and occasionally there seems to be performance
> > problems. The thinking was that maybe some of the
> > perl calls are bumping into each other. For instance
> > a database call may be taking longer then expected.
> > Is there a way I can monitor this? When I have
> > tried to duplicate this it seems that each perl
> > call isnt made until the previous one finishes,
> > from the batch file. Am I incorrect here and
> > there might be other factors at play as far as
> > why performance issues are occuring? Any tools
> > available that I can use to monitor each running
> > perl call? Also since it only happens intermittently
> > I guess I am going to have to capture a lot of data?
> >
> > Thanks in advance for your help!!!
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> > _____________________________________________________________
> > Seattle Perl Users Group Mailing List
> >      POST TO: spug-list at pm.org
> > SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> >     MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
> >     WEB PAGE: http://seattleperl.org/
> >
> >
> 
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>     POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>    MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
>    WEB PAGE: http://seattleperl.org/
>


More information about the spug-list mailing list