dramatiq icon indicating copy to clipboard operation
dramatiq copied to clipboard

For first retry `compute_backoff` always return value below `min_backoff` settings

Open spumer opened this issue 1 year ago • 1 comments

Checklist

  • [x] Does your title concisely summarize the problem?
  • [x] Did you include a minimal, reproducible example?
  • [x] What OS are you using?
  • [x] What version of Dramatiq are you using? - 1.17.0
  • [x] What did you do?
  • [x] What did you expect would happen?
  • [x] What happened?

Dramatiq calculate delay time like this:

            min_backoff = message.options.get("min_backoff", actor.options.get("min_backoff", self.min_backoff))
            max_backoff = message.options.get("max_backoff", actor.options.get("max_backoff", self.max_backoff))
            max_backoff = min(max_backoff, DEFAULT_MAX_BACKOFF)
            _, delay = compute_backoff(retries, factor=min_backoff, max_backoff=max_backoff)

https://github.com/Bogdanp/dramatiq/blob/3e20bdd6c536f56822ce8e224c003b336d555be2/dramatiq/middleware/retries.py#L130

When message retries first time we have a retries = 0 in this scope. Then compute_backoff return value always below min_backoff This happend due default jitter=True flag in compute_backoff function

You can check it manually:

from dramatiq.common import compute_backoff
retries = 0
compute_backoff(retries, factor=1000, max_backoff=5000)
Out[4]: (1, 734)
compute_backoff(retries, factor=1000, max_backoff=5000)
Out[5]: (1, 527)
compute_backoff(retries, factor=1000, max_backoff=5000)
Out[6]: (1, 924)
compute_backoff(retries, factor=1000, max_backoff=5000)
Out[7]: (1, 625)

What OS are you using?

macOS 14.4.1

What version of Dramatiq are you using?

1.17.0

What did you do?

Run task with expected delay

What did you expect would happen?

Delay should be between min_backoff and max_backoff

What happened?

Calculated delay below min_backoff

spumer avatar Sep 12 '24 09:09 spumer

+1 - Seeing this same issue.

swelch1 avatar Jan 02 '25 20:01 swelch1