Skip to content

Conversation

@wk8
Copy link
Contributor

@wk8 wk8 commented Apr 24, 2023

This patch adds a ShouldClaimPendingMessage callback to the subscriber's config, to allow users to decide whether a message that's been pending for more than MaxIdleTime should actually be claimed or not.

My use case for this is that I have a type of async tasks for which the time needed to process one task can vary wildly, anywhere from 1 second to several minutes, and it's impossible to know ahead of time how long it will take. So to avoid long-running instances to be considered dead and be endlessly claimed back & forth, I would have to have a MaxIdleTime of several minutes.
However, that would also meant that it would take that long to detect dead workers, which is also not acceptable for my use case.

This new config option solves this problem by allowing me to have a short MaxIdleTime, but then leverage an external heartbeat mechanism in my ShouldClaimPendingMessage callback to decide if a worker is actually dead, or just busy with a long-running instance of the task.

Added tests on the claim behaviour.

@minghsu0107
Copy link
Collaborator

minghsu0107 commented Apr 24, 2023

This PR looks good! I have one small question:
Why adding the MaxSubscribers config option? What’s the relationship between MaxSubscribers and XPending count?

This patch adds a `ShouldClaimPendingMessage` callback to the
subscriber's config, to allow users to decide whether a message that's
been pending for more than `MaxIdleTime` should actually be claimed or
not.

My use case for this is that I have a type of async tasks for which the
time needed to process one task can vary wildly, anywhere from 1 second
to several minutes, and it's impossible to know ahead of time how long
it will take. So to avoid long-running instances to be considered dead
and be endlessly claimed back & forth, I would have to have a
`MaxIdleTime` of several minutes.
However, that would also meant that it would take that long to detect
dead workers, which is also not acceptable for my use case.

This new config option solves this problem by allowing me to have a
short `MaxIdleTime`, but then leverage an external heartbeat mechanism
in my `ShouldClaimPendingMessage` callback to decide if a worker is
actually dead, or just busy with a long-running instance of the task.

Added tests on the claim behaviour.

Signed-off-by: Jean Rouge <rougej+github@gmail.com>
@wk8 wk8 force-pushed the jrouge/finer_grain_idle branch from decd0c4 to 9f459aa Compare April 24, 2023 16:46
@wk8
Copy link
Contributor Author

wk8 commented Apr 24, 2023

Thanks for the quick review @minghsu0107 ! And you're totally right, MaxSubscribers wasn't needed, removed it :)

@minghsu0107
Copy link
Collaborator

@wk8 I think we can move claimBatchSize to SubscriberConfig and set its default with another variable DefaultClaimBatchSize. This would make it more flexible😎

@wk8
Copy link
Contributor Author

wk8 commented Apr 24, 2023

@minghsu0107 amended as requested :)

@minghsu0107
Copy link
Collaborator

LGTM. Thank you!

@minghsu0107 minghsu0107 merged commit 8644f11 into ThreeDotsLabs:main Apr 25, 2023
@wk8
Copy link
Contributor Author

wk8 commented Apr 25, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants