Skip to content

Worker: support optional batching of log events - #1162

Merged
josephjclark merged 22 commits into
release/workerfrom
batch-logs-3
Dec 10, 2025
Merged

josephjclark merged 22 commits into
release/workerfrom
batch-logs-3

Conversation

@josephjclark

Copy link
Copy Markdown
Collaborator

This PR builds on top of #1161.

It adds batch processing to the new event processor. It basically works like this:

  • Events can be arbitrarily queued. Just pass an option to the processor
  • When an event is queued, we do the following:
    • Set a batch flag to listen for all incoming events
    • Save any batched events to an array
    • Look in the queue to see if there are any other events already queued. If so, add them straight into the batch
    • After 10ms, send the array of batched messages to the listener. A batch listener must be designed to handle an array of events, not just one event
    • If a different event comes through while batching, cancel the timeout, instantly send the batch, and start processing the new event

Fixes #790

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

@josephjclark
josephjclark marked this pull request as draft December 9, 2025 15:27
@github-project-automation github-project-automation Bot moved this to New Issues in Core Dec 9, 2025
@josephjclark

Copy link
Copy Markdown
Collaborator Author

It doesn't look like the interval stuff is actually working. I'll either disable that option (do we really need it?) or try and get it fixed tomorrow

@josephjclark

Copy link
Copy Markdown
Collaborator Author

TODO need to add more integration level tests around batching. I've made the log handler robust to batch and non batch, which basically means that most of the tests are in non batch mode.

I need to either add a few explicit batch tests, or make batching default in all tests. For the sake of an easier life I think I'll just add a few new tests

@josephjclark
josephjclark changed the base branch from main to release/worker December 10, 2025 09:07
@josephjclark

Copy link
Copy Markdown
Collaborator Author

from speaking with Stu: not to worried about the size of log payloads on the wire

raise an issue to take size into account later. Maybe track batch size or break batch on a large payload

Let's be a bit daring and set the default batch to 50. Easy to modify

@josephjclark

josephjclark commented Dec 10, 2025 •

Copy link
Copy Markdown
Collaborator Author

When enabling batch logs by default on the worker, we should make that a breaking change (because not all lightning versions will be compatible)

Alternatively, negotiate support with lightning when joining the run channel, so that we ensure compatiblity

@josephjclark josephjclark mentioned this pull request Dec 10, 2025
1 of 7 tasks
@josephjclark
josephjclark marked this pull request as ready for review December 10, 2025 12:02
@josephjclark

Copy link
Copy Markdown
Collaborator Author

Persistent integration test fails in CI. Having a hard time figuring this out - seems OK locally. I am finding a strange exception getting thrown so looking into that...

@josephjclark josephjclark changed the title New batch logger Worker: support optional batching of log events Dec 10, 2025
@josephjclark

Copy link
Copy Markdown
Collaborator Author

Phew. Finally got this passing. A bit of docs then I can merge

@josephjclark
josephjclark merged commit 3a7038b into release/worker Dec 10, 2025
1 check was pending
@josephjclark
josephjclark deleted the batch-logs-3 branch December 10, 2025 15:06
@github-project-automation github-project-automation Bot moved this from New Issues to Done in Core Dec 10, 2025
josephjclark added a commit that referenced this pull request Dec 11, 2025
* Log limits (#1156)

* engine: support payload limits per event

* add log limit tests

* tests

* type

* changeset

* formatting

* update changeset

* remove rubbish

* Engine: try to make calculating payload sizes more efficient (#1155)

* scaffolding: make ensure-payload-size async and add slots for two algorithms

* first swing at async traversal

This actually increases memory overhead

* new traversal algorithm with queue, rather than recuion

* add benchmarking util

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* tidying

* optimisations

Still doesn't get close

* add streaming algo

* update benchmark

* remove traversal algorithm

* tidy

* tidy up

* tidy docs

* remove ignore

* remove old traverse stats

* typing

* restore await

* add a synchronous publish option

important  for process exit events

* revert debug code

---------

Co-authored-by: Claude <noreply@anthropic.com>

* Worker: support optional batching of log events (#1162)

* worker: re-write core event handler to allow more control of sequencing

* tidy tests and finish

* types

* add basic tests

* more testing

* Add batching and tests

* more tests

* options and more tests

* types

* copy new log stuff from other branch

* updates for live testing against lightning

Works great against new and legacy app, with or without batching

* options for interval and limit

* fix test

* copy across old test

* fix type

* add batch log test

* upate default batch size

* changeset

* run integration tests in batch mode

* update tests

* remove logging

* docs

* versions: worker@1.20.

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Worker: batch log events

1 participant