Skip to content

Make lingerMillis and capacity dynamic for BatchingProcessor#268

Merged
ocadaruma merged 9 commits intoline:masterfrom
kun98-liu:batching-dynamic
Jan 5, 2026
Merged

Make lingerMillis and capacity dynamic for BatchingProcessor#268
ocadaruma merged 9 commits intoline:masterfrom
kun98-liu:batching-dynamic

Conversation

@kun98-liu
Copy link
Contributor

Currently, BatchingProcessor takes lingerMillis and capacity through its constructor, and they can't be changed during runtime.

To put this into production, it would be nice for them to be configurable during runtime, so that user can tune them like changing ProcessorProperty.

I took an attempt to make them into ProcessorProperty, but couldn't make it. So this PR is to use Supplier for them, so that user can inject the configuration by themselves.

@CLAassistant
Copy link

CLAassistant commented Nov 25, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@ocadaruma ocadaruma 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 the patch! and sorry for the late review.

The change looks very useful.
I left some feedbacks. PTAL

protected BatchingProcessor(long lingerMillis, int capacity) {
this.lingerMillis = lingerMillis;
this.capacity = capacity;
protected BatchingProcessor(Supplier<Long> lingerMillisSupplier, Supplier<Integer> capacitySupplier) {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest keep current constructor to avoid breaking change, by adding overload like BatchingProcessor(lingerMillis, capacity) { this(() -> lingerMillis, () -> capacity) ... }


private void scheduleFlush() {
executor.schedule(this::periodicallyFlushTask, lingerMillis, TimeUnit.MILLISECONDS);
executor.schedule(this::periodicallyFlushTask, this.lingerMillisSupplier.get(), TimeUnit.MILLISECONDS);
Copy link
Member

Choose a reason for hiding this comment

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

Just getting new value and use it might be unsafe when supplier returns invalid value like negative value.

I suggest add a validation, and when it fails, logs it and keep using current value. WDYT? (Yeah I know, even the current code also doesn't have validation though...)
for capacity as well.

Copy link
Contributor Author

@kun98-liu kun98-liu Dec 27, 2025

Choose a reason for hiding this comment

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

EDIT:
I thought adding validations for extreme large numbers would be useful, but actually it could be intended in some cases. So let me add non-negative validations and error handling when get() throws exceptions

@kun98-liu kun98-liu requested a review from ocadaruma December 29, 2025 06:55
Copy link
Member

@ocadaruma ocadaruma left a comment

Choose a reason for hiding this comment

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

Just left minor feedbacks. overall LGTM!

executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
}

private <V> Supplier<V> validatedAndLKGWrappedSupplier(
Copy link
Member

Choose a reason for hiding this comment

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

can be static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 yes and updated.

try {
value = delegate.get();
} catch (Exception e) {
if (lkg != null && lkg.get() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

[nits] IMO null check of lkg is redundant, because it's obvious that callers don't pass null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, i removed it from argument and create it inside this method. since there is no need for caller to pass it in.

Copy link
Member

@ocadaruma ocadaruma left a comment

Choose a reason for hiding this comment

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

LGTM. Nice!

@ocadaruma ocadaruma merged commit 323de97 into line:master Jan 5, 2026
6 checks passed
@ocadaruma ocadaruma added the new feature Add a new feature label Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Add a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants