chore: improvements around dynamic scaling of sharded daemon processes - #1437
chore: improvements around dynamic scaling of sharded daemon processes#1437johanandren wants to merge 2 commits into
Conversation
| daemonContext -> { | ||
| var sliceRanges = | ||
| EventSourcedProvider.sliceRanges( | ||
| system, R2dbcReadJournal.Identifier(), daemonContext.totalProcesses()); |
There was a problem hiding this comment.
why do we use EventSourcedProvider here and in some other places
Persistence(system).sliceRanges(context.totalProcesses)
would be easier to always use Persistence.sliceRanges?
There was a problem hiding this comment.
21 places across projections samples and specs (!!)
There was a problem hiding this comment.
What it adds is looking up the read journal for that specific plugin/config, so that the actual journal could have some other slicing scheme.
But in practice it is always the same, so should we always use the simpler one? In that case, why does the EventSourcedProvider#sliceRanges even exist?
PR adding the method didn't shed any light on it #609
There was a problem hiding this comment.
ok, I would guess that the guy thought it would be nice to stay within projections api surface and not reach out to persistence. It's typically used together with
EventSourcedProvider.eventsBySlices(
system,
R2dbcReadJournal.Identifier(),
PRODUCER_ENTITY_TYPE,
sliceRange.first(),
sliceRange.second());
Let's leave it as is, using EventSourcedProvider#sliceRanges
There was a problem hiding this comment.
Might look better to move the whole slice range stuff into the projection method, and just pass the totalProcesses to that method, but not very important.
|
|
||
| ShardedDaemonProcess.get(system) | ||
| .init( | ||
| .initWithContext( |
There was a problem hiding this comment.
do we want to promote initWithContext in all places, even if scaling isn't used/needed? the signature looks more complex than init?
There was a problem hiding this comment.
Hmm, good point, I went for all the places to make sure anything users could copy paste is safe to evolve/scale, but maybe that is overdoing it.
ShardedDaemonProcesskeeps the current number of processes in distributed data, and the(initial)NumberOfInstancesargument is only used on first start. Several gRPC projection samples and the internalReplicationImplcomputedsliceRangesoutside the behavior factory, sized by the configured number. If ddata held a different (e.g. previously rescaled) count, processes with a processNumber outside the configured range would crash withIndexOutOfBoundsExceptionon every keep-alive tick, silently degrading the projection to only the lowest-numbered instances doing useful work.This PR migrates all affected sites to the pattern already used by the r2dbc/dynamodb doc examples: compute
sliceRangesinside the factory fromdaemonContext.totalProcesses, and useinitWithContextso it picks up rescale events.The samples don't do rescaling themselves but could end up being the starting point for users who later would do rescaling.