Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(queues): best effort batching during shutdown #11376

Merged
merged 5 commits into from
Aug 17, 2023

Conversation

JensErat
Copy link
Contributor

@JensErat JensErat commented Aug 9, 2023

Summary

During worker shutdown, batching was stopped entirely. Even if hundreds or thousands of queued items are waiting to be processed, no batches would have been built but hundreds or thousands of individual handler calls executed sequentially (potentially resulting in forced shutdown due to added up latency).

By not stopping batching entirely, but instead falling back to the minimal coalescing time already defined, we still allow best-effort batching, which will optimize shutdown queue flush behavior.

I added two commits: the first added a (failing) test to show batching is broken, the other one fixes batching again.

This is a pretty minimal change and rather optimization, not a bugfix. Do we need a changelog entry/... for this?

Checklist

Jens Erat <jens.erat@mercedes-benz.com>, Mercedes-Benz Tech Innovation GmbH, imprint

@CLAassistant
Copy link

CLAassistant commented Aug 9, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hanshuebner
Copy link
Contributor

Thank you for this fix - I would qualify it as a bug fix as in the scenarios where it helps, the non-batching behavior would be unexpected. In any case, a CHANGELOG entry should be added.

Copy link
Contributor

@hanshuebner hanshuebner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a CHANGELOG entry. Looks good otherwise

@JensErat
Copy link
Contributor Author

Rebased to get the "unreleased" section of the changelog and added the changelog entry. Should I squash the commits, or is this done when merging?

The new batch queue completely disables batch processing during shutdown. When queue entries are sent to a backend service, the accumulated sequential callback execution time will likely exceed the forced shutdown timeout and some data lost.
The new batch queue completely disables batch processing during shutdown. When queue entries are sent to a backend service, the accumulated sequential callback execution time will likely exceed the forced shutdown timeout and some data lost.
@JensErat JensErat force-pushed the try-to-batch-during-shutdown branch from 4d3e8a3 to adedeb4 Compare August 15, 2023 09:09
@hanshuebner
Copy link
Contributor

@JensErat Sorry, there are new conflicts in your PR that need to be resolved. Once done, I'll squash when I merge the PR.

@JensErat
Copy link
Contributor Author

@JensErat Sorry, there are new conflicts in your PR that need to be resolved. Once done, I'll squash when I merge the PR.

Done, luckily only the changelog was affected.

@hanshuebner
Copy link
Contributor

Thanks. We're working on changing how CHANGELOGs work to avoid such trivial conflicts in the future. Will merge after tests have passed.

@hanshuebner hanshuebner merged commit b3041be into Kong:master Aug 17, 2023
21 checks passed
chronolaw added a commit that referenced this pull request Aug 24, 2023
hanshuebner added a commit that referenced this pull request Aug 25, 2023
The previous fix (#11376) to enable batching during shutdown failed to check
the shutdown flag while waiting for more items to batch.  If the coalescing
delay was large enough, this could cause the last batch to be lost.
hanshuebner added a commit that referenced this pull request Aug 25, 2023
The previous fix (#11376) to enable batching during shutdown failed to check
the shutdown flag while waiting for more items to batch.  If the coalescing
delay was large enough, this could cause the last batch to be lost.
hanshuebner added a commit that referenced this pull request Sep 20, 2023
The previous fix (#11376) to enable batching during shutdown failed to check
the shutdown flag while waiting for more items to batch.  If the coalescing
delay was large enough, this could cause the last batch to be lost.

(cherry picked from commit 3bf77d7)
hanshuebner added a commit that referenced this pull request Sep 20, 2023
The previous fix (#11376) to enable batching during shutdown failed to check
the shutdown flag while waiting for more items to batch.  If the coalescing
delay was large enough, this could cause the last batch to be lost.

(cherry picked from commit 3bf77d7)
hanshuebner added a commit that referenced this pull request Sep 20, 2023
…#11607)

The previous fix (#11376) to enable batching during shutdown failed to check
the shutdown flag while waiting for more items to batch.  If the coalescing
delay was large enough, this could cause the last batch to be lost.

(cherry picked from commit 3bf77d7)

Co-authored-by: Hans Hübner <hans.huebner@gmail.com>
hanshuebner added a commit that referenced this pull request Sep 20, 2023
…#11608)

The previous fix (#11376) to enable batching during shutdown failed to check
the shutdown flag while waiting for more items to batch.  If the coalescing
delay was large enough, this could cause the last batch to be lost.

(cherry picked from commit 3bf77d7)

Co-authored-by: Hans Hübner <hans.huebner@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants