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

Highest applied sequence number is only updated after full replay/catchup #261

Closed
bwaidelich opened this issue Mar 15, 2020 · 1 comment
Closed
Assignees
Labels
Projects
Milestone

Comments

@bwaidelich
Copy link
Member

@bwaidelich bwaidelich commented Mar 15, 2020

Since #159 the AppliedEventsStorage implementation is transaction safe – so it allows multiple workers to run the projection:replayall command at the same time without violating the "exactly once semantics"¹.

The drawback of the current implementation: Everything is wrapped in a transaction that is only committed at the end of EventListenerInvoker::catchup().
So replaying/catching up event listeners for thousands of events end up creating a huge transaction and the neos_eventsourcing_eventlistener_appliedeventslog entry is only updated at the end of the process.. if everything went well.

To solve this we should commit the transaction for every event instead.

Bonus: allow the batch size to be changed for faster replays/catchups

--
¹ that is if the affected projections act on the same database connection

@bwaidelich bwaidelich added the 🐞 Bug label Mar 15, 2020
@bwaidelich bwaidelich added this to the 2.0 milestone Mar 15, 2020
@bwaidelich bwaidelich self-assigned this Mar 15, 2020
@bwaidelich bwaidelich added this to TODO in 2.0 via automation Mar 15, 2020
@albe

This comment has been minimized.

Copy link
Member

@albe albe commented Mar 15, 2020

+1 for batch size, as one transaction per event will also be far from optimal in such a scenario. The trade-off is catch-up speed vs. making progress (not doing work that has no effect)

bwaidelich added a commit to bwaidelich/Neos.EventSourcing that referenced this issue Mar 20, 2020
Previously the whole `EventListenerInvoker::catchup()` call triggered a
single blocking transaction that was only committed when the corresponding
event listener was up to date with the event store.
Especially for replays and initial catchups this posed a problem because
of the ever growing transaction.

With this change the "Highest Applied Sequence Number" is released after
each applied event.
This has the nice side effect that multiple workers can share the load:
While process 1 commits the transaction, process 2 can already start processing
the next event.

For batch-processing the batch size can be increased in order to improve performance:

    $eventListenerInvoker = (new EventListenerInvoker($eventStore, $listener, $connection))
       ->withTransactionBatchSize(500)
       ->catchup()

This is a breaking change because the signature of the `EventListenerInvoker` has
changed slightly:

Previously:

    $eventListenerInvoker = new EventListenerInvoker($eventStore);
    $eventListenerInvoker->catchup($listener, $progressCallback);

Now:

    $eventListenerInvoker = new EventListenerInvoker($eventStore, $listener, $connection);
    $eventListenerInvoker->onProgress($eventListenerInvoker);
    $eventListenerInvoker->catchup();

Fixes: neos#261
2.0 automation moved this from TODO to Done Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2.0
  
Done
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.