NAME

show-backoff-delays - Show backoff delays

VERSION

This document describes version 0.005 of show-backoff-delays (from Perl distribution App-AlgorithmBackoffUtils), released on 2020-10-20.

SYNOPSIS

Usage:

% show-backoff-delays [-a=s] [--algorithm=s] [--consider-actual-delay]
    [--debug] [--delay-increment-on-failure=s]
    [--delay-increment-on-success=s] [--delay-multiple-on-failure=s]
    [--delay-multiple-on-success=s] [--delay-on-success=s] [--delay=s]
    [--dry-run] [--exponent-base=s] [--format=name] [--initial-delay1=s]
    [--initial-delay2=s] [--initial-delay=s] [--jitter-factor=s] [--json]
    [--log-level=level] [--log=s+] [--logs-json=s]
    [--max-actual-duration=s] [--max-attempts=s] [--max-delay=s]
    [--min-delay=s] [--(no)naked-res] [--no-consider-actual-delay]
    [--noconsider-actual-delay] [--page-result[=program]] [--quiet]
    [--trace] [--verbose] <log> ...

OPTIONS

* marks required options.

Main options

--algorithm=s*, -a

Backoff algorithm.

Valid values:

["Constant","Exponential","Fibonacci","LILD","LIMD","MILD","MIMD"]
--log=s@*

List of failures or successes.

A list of 0's (to signify failure) or 1's (to signify success). Each failure/success can be followed by `:TIMESTAMP` (unix epoch) or `:+SECS` (number of seconds after the previous log), or the current timestamp will be assumed. Examples:

0 0 0 0 0 0 0 0 0 0 1 1 1 1 1

(10 failures followed by 5 successes).

0 0:+2 0:+4 0:+6 1

(4 failures, 2 seconds apart, followed by immediate success.)

Can be specified multiple times.

--logs-json=s

List of failures or successes (JSON-encoded).

See --log.

Common to all algorithms options

--consider-actual-delay

Whether to consider actual delay.

If set to true, will take into account the actual delay (timestamp difference). For example, when using the Constant strategy of delay=2, you log failure() again right after the previous failure() (i.e. specify the same timestamp). failure() will then return ~2+2 = 4 seconds. On the other hand, if you waited 2 seconds before calling failure() again (i.e. specify the timestamp that is 2 seconds larger than the previous timestamp), failure() will return 2 seconds. And if you waited 4 seconds or more, failure() will return 0.

--jitter-factor=s

How much to add randomness.

If you set this to a value larger than 0, the actual delay will be between a random number between original_delay * (1-jitter_factor) and original_delay * (1+jitter_factor). Jitters are usually added to avoid so-called "thundering herd" problem.

The jitter will be applied to delay on failure as well as on success.

--max-actual-duration=s

Maximum number of seconds for all of the attempts (0 means unlimited).

Default value:

0

If set to a positive number, will limit the number of seconds for all of the attempts. This setting is used to limit the amount of time you are willing to spend on a task. For example, when using the Exponential strategy of initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If failures are logged according to the suggested delays, and max_actual_duration is set to 21 seconds, then the third failure() will return -1 instead of 24 because 3+6+12 >= 21, even though max_attempts has not been exceeded.

--max-attempts=s

Maximum number consecutive failures before giving up.

Default value:

0

0 means to retry endlessly without ever giving up. 1 means to give up after a single failure (i.e. no retry attempts). 2 means to retry once after a failure. Note that after a success, the number of attempts is reset (as expected). So if max_attempts is 3, and if you fail twice then succeed, then on the next failure the algorithm will retry again for a maximum of 3 times.

--max-delay=s

Maximum delay time, in seconds.

--min-delay=s

Maximum delay time, in seconds.

Default value:

0

Constant algorithm options

--delay-on-success=s

Number of seconds to wait after a success.

Default value:

0
--delay=s

Number of seconds to wait after a failure.

Exponential algorithm options

--delay-on-success=s

Number of seconds to wait after a success.

Default value:

0
--exponent-base=s

Default value:

2
--initial-delay=s

Initial delay for the first attempt after failure, in seconds.

Fibonacci algorithm options

--delay-on-success=s

Number of seconds to wait after a success.

Default value:

0
--initial-delay1=s

Initial delay for the first attempt after failure, in seconds.

--initial-delay2=s

Initial delay for the second attempt after failure, in seconds.

Lild algorithm options

--delay-increment-on-failure=s

How much to add to previous delay, in seconds, upon failure (e.g. 5).

--delay-increment-on-success=s

How much to add to previous delay, in seconds, upon success (e.g. -5).

--initial-delay=s

Initial delay for the first attempt after failure, in seconds.

Limd algorithm options

--delay-increment-on-failure=s

How much to add to previous delay, in seconds, upon failure (e.g. 5).

--delay-multiple-on-success=s

How much to multiple previous delay, upon success (e.g. 0.5).

--initial-delay=s

Initial delay for the first attempt after failure, in seconds.

Logging options

--debug

Shortcut for --log-level=debug.

--log-level=s

Set log level.

--quiet

Shortcut for --log-level=error.

--trace

Shortcut for --log-level=trace.

--verbose

Shortcut for --log-level=info.

Mild algorithm options

--delay-increment-on-success=s

How much to add to previous delay, in seconds, upon success (e.g. -5).

--delay-multiple-on-failure=s

How much to multiple previous delay, upon failure (e.g. 1.5).

--initial-delay=s

Initial delay for the first attempt after failure, in seconds.

Mimd algorithm options

--delay-multiple-on-failure=s

How much to multiple previous delay, upon failure (e.g. 1.5).

--delay-multiple-on-success=s

How much to multiple previous delay, upon success (e.g. 0.5).

--initial-delay=s

Initial delay for the first attempt after failure, in seconds.

Output options

--format=s

Choose output format, e.g. json, text.

Default value:

undef
--json

Set output format to json.

--naked-res

When outputing as JSON, strip result envelope.

Default value:

0

By default, when outputing as JSON, the full enveloped result is returned, e.g.:

[200,"OK",[1,2,3],{"func.extra"=>4}]

The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use `--naked-res` so you just get:

[1,2,3]
--page-result

Filter output through a pager.

Other options

--dry-run

Run in simulation mode (also via DRY_RUN=1).

Default value:

""
--help, -h, -?

Display help message and exit.

--version, -v

Display program's version and exit.

COMPLETION

This script has shell tab completion capability with support for several shells.

bash

To activate bash completion for this script, put:

complete -C show-backoff-delays show-backoff-delays

in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.

tcsh

To activate tcsh completion for this script, put:

complete show-backoff-delays 'p/*/`show-backoff-delays`/'

in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is also recommended to install shcompgen (see above).

other shells

For fish and zsh, install shcompgen as described above.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-AlgorithmBackoffUtils.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-AlgorithmBackoffUtils.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-AlgorithmBackoffUtils

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Algorithm::Backoff::Fibonacci.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020, 2019 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.