Skip to content
/ eb Public

♻️ Run commands with exponential backoff πŸ“ˆ

License

Notifications You must be signed in to change notification settings

rye/eb

This branch is 1 commit ahead of main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6a3d9f9 Β· Jan 28, 2025
Dec 17, 2024
Dec 21, 2022
Aug 8, 2021
Jul 11, 2019
Jun 13, 2020
Jul 11, 2019
Jan 23, 2020
Jan 28, 2025
Jan 28, 2025
Jul 11, 2019
Oct 4, 2021
Apr 20, 2023

Repository files navigation

eb

eb is a small utility that runs a command with exponential backoff.

eb only exits once a status code of 0 has been returned by the command it is calling, or once killed by a Ctrl+C or other signal.

You can use eb much like watch:

$ eb -- ssh -oConnectTimeout=0 host

Installing it

You can install eb via

$ cargo install eb

and you can update it via the same command.

Features

We currently support these (cargo) features:

  • simple_logger enables the simple_logger logger.

There are no features enabled by default.

The algorithm

In the above console input, eb will watch the command and keep track of how long it takes to fail. Upon the first failure, a "slot time" is set to the time it took for the command to fail.

In each instance, after n failures, a random number of slot times between 0 and 2^n - 1 is chosen, and these slot times are delayed through. So, after the first failure, eb will either wait 0 or 1 slot times; after the second failure this number increases to between 0 and 3. The exponent n is clamped to be within the range 0 and MAX_N where MAX_N is some predefined number; in our case this is 10. In practice, this means that after 10 collisions, the possible upper bound on delay does not increase. Because commands take a variable amount of time to complete, the slot time is adjusted to be the average of all execution times. The delay will start very quickly after the command fails.

Because of the way the algorithm works, it is recommended to use eb in situations where the given command will fail quickly. This will result in a proportionally small maximum delay time.

License

eb: A command executor exercising exponential backoff
Copyright (C) 2019-2021 Kristofer J. Rye

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

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.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.