10 个不稳定版本 (4 个破坏性更新)
| 0.5.0 | 2021年10月4日 |
|---|---|
| 0.4.0 | 2021年8月8日 |
| 0.3.5 | 2020年4月21日 |
| 0.3.2 | 2020年3月25日 |
| 0.1.0 | 2019年7月11日 |
#1512 in 命令行实用工具
22KB
265 行
eb
eb 是一个小的实用工具,用于带有指数退避的命令执行。
eb 仅在它调用的命令返回状态码 0 或被 Ctrl+C 或其他信号终止时退出。
您可以使用 eb 就像使用 watch 一样。
$ eb -- ssh -oConnectTimeout=0 host
安装它
您可以通过以下方式安装 eb:
$ cargo install eb
并且您可以通过相同的命令更新它。
功能
我们目前支持以下 (cargo) 功能
simple_logger启用simple_logger记录器。
默认情况下没有启用任何功能。
算法
在上面的控制台输入中,eb 将监视命令并跟踪其失败所需的时间。第一次失败时,将“槽时间”设置为命令失败所需的时间。
在每次实例中,在 n 次失败之后,选择一个介于 0 和 2^n - 1 之间的随机槽时间,并通过这些槽时间进行延迟。因此,第一次失败后,eb 将等待 0 或 1 个槽时间;第二次失败后,这个数字增加到 0 到 3 之间。指数 n 被限制在 0 和 MAX_N 的范围内,其中 MAX_N 是某个预定义的数字;在我们的情况下,这是 10。在实践中,这意味着在 10 次碰撞后,延迟的上限不会增加。由于命令完成所需的时间是可变的,因此槽时间调整为所有执行时间的平均值。延迟将在命令失败后开始得非常快。
由于算法的工作方式,建议在给定命令会快速失败的情况下使用 eb。这将导致最大延迟时间成比例地较小。
许可证
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/>.
依赖项
~1.4–2.4MB
~36K SLoC