++ed by:
MATTK ABRAXXA MISHIN SYP EMAZEP

5 PAUSE users
2 non-PAUSE users.

Steffen Müller

NAME

IPC::ConcurrencyLimit::WithStandby - IPC::ConcurrencyLimit with an additional standby lock

SYNOPSIS

  use IPC::ConcurrencyLimit::WithStandby;
  
  sub run {
    my $limit = IPC::ConcurrencyLimit->new(
      type              => 'Flock', # that's also the default
      max_procs         => 10,
      path              => '/var/run/myapp',
      standby_path      => '/var/run/myapp/standby',
      standby_max_procs => 3,
    );
    
    my $id = $limit->get_lock;
    if (not $id) {
      warn "Got none of the worker locks. Exiting.";
      exit(0);
    }
    else {
      # Got one of the worker locks (ie. number $id)
      do_work();
    }
    
    # lock released with $limit going out of scope here
  }
  
  run();
  exit();

DESCRIPTION

This module provides the same interface as the regular IPC::ConcurrencyLimit module. It differs in what happens if get_lock fails to get a slot for the main limit:

If it fails to get a (or the) lock on the main limit, it will repeatedly attempt to get the main lock until a slot for the main limit is attained or the number of retries is exhausted. Most importantly, this supports limiting the number of instances that continuously attempt to get the main lock (typically, this would be limited to 1). This is implemented with a wait-retry-loop and two separate IPC::ConcurrencyLimit objects.

The options for the main limit are passed in to the constructor as usual. The standby limit are inherited from the main one, but all parameters prefixed with standby_ will override the respective inherited parameters. For example, standby_type => "MySQL" will enforce the use of the MySQL lock for the standby lock.

In addition to the regular IPC::ConcurrencyLimit options, the constructor accepts retries as the number of retries a standby instance should do to get the main lock. There will always be only one attempt to become a standby process. Additionally, interval can indicate a number of seconds to wait between retries (also supports fractional seconds down to what Time::HiRes::sleep supports).

AUTHOR

Steffen Mueller, smueller@cpan.org

ACKNOWLEDGMENT

This module was originally developed for booking.com. With approval from booking.com, this module was generalized and put on CPAN, for which the authors would like to express their gratitude.

COPYRIGHT AND LICENSE

 (C) 2012 Steffen Mueller. All rights reserved.
 
 This code is available under the same license as Perl version
 5.8.1 or higher.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.