From 36ec1bb7c057183af0679f65bbc9654a81807f49 Mon Sep 17 00:00:00 2001 From: Liran M <77168114+liran2000@users.noreply.github.com> Date: Mon, 11 Sep 2023 20:21:31 +0300 Subject: [PATCH] feat: ISSUE-228 random - document as Jitter (#376) * feat: ISSUE-228 random - document as Jitter Signed-off-by: liran2000 * fix build format Signed-off-by: liran2000 * Decapitalize jitter. --------- Signed-off-by: liran2000 Co-authored-by: Gary Russell --- README.md | 2 +- .../java/org/springframework/retry/annotation/Backoff.java | 4 ++-- .../retry/backoff/ExponentialRandomBackOffPolicy.java | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6318b1e..19bdd43 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ back off with an exponentially increasing wait period, to avoid two retries gett lock step and both failing (a lesson learned from Ethernet). For this purpose, Spring Retry provides `ExponentialBackoffPolicy`. Spring Retry also provides randomized versions of delay policies that are quite useful to avoid resonating between related failures in a -complex system. +complex system, by adding jitter. ## Listeners diff --git a/src/main/java/org/springframework/retry/annotation/Backoff.java b/src/main/java/org/springframework/retry/annotation/Backoff.java index 17610de..06c366f 100644 --- a/src/main/java/org/springframework/retry/annotation/Backoff.java +++ b/src/main/java/org/springframework/retry/annotation/Backoff.java @@ -116,8 +116,8 @@ public @interface Backoff { /** * In the exponential case ({@link #multiplier()} > 0) set this to true to have the - * backoff delays randomized, so that the maximum delay is multiplier times the - * previous delay and the distribution is uniform between the two values. + * backoff delays randomized with jitter, so that the maximum delay is multiplier + * times the previous delay and the distribution is uniform between the two values. * @return the flag to signal randomization is required (default false) */ boolean random() default false; diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialRandomBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialRandomBackOffPolicy.java index 70dc14f..2dcc9b1 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialRandomBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialRandomBackOffPolicy.java @@ -26,7 +26,8 @@ import org.springframework.retry.RetryContext; * that chooses a random multiple of the interval that would come from a simple * deterministic exponential. The random multiple is uniformly distributed between 1 and * the deterministic multiplier (so in practice the interval is somewhere between the next - * and next but one intervals in the deterministic case). + * and next but one intervals in the deterministic case). This is often referred to as + * jitter. * * This has shown to at least be useful in testing scenarios where excessive contention is * generated by the test needing many retries. In test, usually threads are started at the