Skip to content

[Utils] Add a batch policy utility #12430

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

Merged
merged 3 commits into from
Mar 25, 2025
Merged

[Utils] Add a batch policy utility #12430

merged 3 commits into from
Mar 25, 2025

Conversation

gregfurman
Copy link
Contributor

@gregfurman gregfurman commented Mar 24, 2025

Motivation

Multiple services require data to be batched before further processing. Where batches can be collected based on:

  • The number of records observed/collected (Batch count)
  • A specified time-interval (Batch window)
  • The number of underlying bytes collected (Batch size)
  • Some other artibrary condition (i.e when a certain attribute is encountered then create a new batch)

To solve this problem, the new batcher utility class aims to standardize how we collect and return data needing to be batched. This has the following benefits:

  • Standardizes a batching approach that can be re-used across multiple components
  • Extendability allows us future versions to define custom batch policies that can be triggered on artibrary data.

Changes

  • Adds a new Batcher utility that allows us to define a batch policy and collect and batch records based:
    • The number of records collected (batch count) and;
    • The duration for which a batch is being collected for (batch window)

Testing

  • Added tests/unit/utils/test_batch_policy.py

@gregfurman gregfurman added area: performance Make LocalStack go rocket-fast semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases aws:lambda:event-source-mapping AWS Lambda Event Source Mapping (ESM) labels Mar 24, 2025
@gregfurman gregfurman added this to the 4.3 milestone Mar 24, 2025
@gregfurman gregfurman requested a review from tiurin March 24, 2025 15:18
@gregfurman gregfurman self-assigned this Mar 24, 2025
@gregfurman gregfurman changed the title [ESM] Support Stream Poller batching with batcher utility class [ESM] Support Stream Poller batching Mar 24, 2025
@gregfurman gregfurman force-pushed the add/util/batch-policy branch from 79454bb to 4b03952 Compare March 24, 2025 16:23
@gregfurman gregfurman force-pushed the add/util/batch-policy branch from 4b03952 to 009bff4 Compare March 24, 2025 16:26
Copy link

github-actions bot commented Mar 24, 2025

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 51m 11s ⏱️ - 1m 36s
4 305 tests ±0  3 984 ✅ ±0  321 💤 ±0  0 ❌ ±0 
4 307 runs  ±0  3 984 ✅ ±0  323 💤 ±0  0 ❌ ±0 

Results for commit 399b60d. ± Comparison against base commit 08382d0.

♻️ This comment has been updated with latest results.

@gregfurman gregfurman marked this pull request as ready for review March 24, 2025 17:31
@gregfurman gregfurman force-pushed the add/util/batch-policy branch from 009bff4 to a795145 Compare March 25, 2025 09:15
@gregfurman gregfurman changed the title [ESM] Support Stream Poller batching [Utils] Add a batch policy utility Mar 25, 2025
Copy link
Contributor

@tiurin tiurin left a comment

Choose a reason for hiding this comment

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

Great utility class @gregfurman! 👏

My comments are mostly about naming, docstrings and constraints. Happy to discuss.

Copy link
Member

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

Great review from @tiurin 👍

Not much to add. Well done 👏

@gregfurman gregfurman force-pushed the add/util/batch-policy branch from 4f20d8d to 6ed957b Compare March 25, 2025 15:56
Copy link
Contributor

@tiurin tiurin left a comment

Choose a reason for hiding this comment

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

Thank you for addressing all non-blocking comments! 👍

@gregfurman gregfurman merged commit c6096d8 into master Mar 25, 2025
31 checks passed
@gregfurman gregfurman deleted the add/util/batch-policy branch March 25, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: performance Make LocalStack go rocket-fast aws:lambda:event-source-mapping AWS Lambda Event Source Mapping (ESM) semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants