Git Product home page Git Product logo

backoffv2's Introduction

BackoffV2 Build Status


BackoffV2 is a PHP 5.5+ library implementing various backoff algorithms, such as exponential backoff.

This library only returns a backoff delay amount based on the selected algorithms; implementation of the actual delay mechanism (such as sleep()) is left to the user.


Installation

Install BackoffV2 with Composer:

composer require patinthehat/backoffv2


Implementation

"Jitter" is implemented, if you choose to use it. Jitter is a small, variable amount of time that is added to the backoff amount.


Available Jitter algorithms (roughly based on this post) include:

  • NoJitter - No jitter
  • FullJitter - Standard jitter amount
  • EqualJitter - More consistent jitter amounts
  • DecorrelatedJitter - Higher jitter amounts

Backoff algorithms include:

  • ExponentialBackoff - exponentially increase the backoff amount
  • ConstantBackoff - use the same backoff amount, regardless of the attempt count.
  • LinearBackoff - linear increase of the backoff amount, i.e. 1, 2, 3, 4, ...

Usage


Using the Backoff class

BackoffV2 implements a main class, Backoff, that acts as a container and manager for the backoff and jitter algorithms you choose. The constructor signature for Backoff is:

public function __construct($maxBackoff, BackoffStrategyInterface $backoff, JitterStrategyInterface $jitter)

Usage is simple:

include 'vendor/autoload.php';
use BackoffV2\Backoff;
use BackoffV2\Backoff\ExponentialBackoff;
use BackoffV2\Jitter\FullJitter;

$b = new Backoff(15, new ExponentialBackoff, new FullJitter);

echo 'backoff = '.$b->getBackoff() . PHP_EOL;
echo 'backoff = '.$b->getBackoff() . PHP_EOL;
echo 'backoff = '.$b->getBackoff() . PHP_EOL;
echo 'backoff = '.$b->getBackoff() . PHP_EOL;
echo 'backoff = '.$b->getBackoff() . ' (attempt ' . $b->getAttempt().')' . PHP_EOL;
$b->reset();

License

BackoffV2 is available under the MIT License.

backoffv2's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.