Repository navigation
timesync: time coordinator, O(N) instead of O(N²) sync traffic - #461
Open
KonradBreitsprecherBkd wants to merge 4 commits into
Open
KonradBreitsprecherBkd wants to merge 4 commits into
KonradBreitsprecherBkd wants to merge 4 commits into
Conversation
…O(N²) to O(N) Today every synchronized participant broadcasts its NextSimTask to every other synchronized participant, which costs O(N²) messages per simulation step. With Experimental.TimeSynchronization.TimeCoordinator set on one participant, all synchronized participants send their NextSimTask to the coordinator only. The coordinator grants the next time advance, as a NextSimTask, to the participants whose next step is the earliest in the simulation. That is the same rule as the distributed algorithm, so the order of simulation steps does not change. The API is unchanged. - Announced in service discovery (TimeSyncCoordinator=1); participants switch to coordinated mode when they discover the coordinator. - New capability "time-coordination". A synchronized participant without it aborts the simulation, as does a second coordinator or a coordinator that joins after the virtual time has started. - Supports sync and async step handlers, dynamic step sizes and autonomous hop-on / hop-off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Konrad Breitsprecher <Konrad.Breitsprecher@vector.com>
…ment window --time-coordinator makes Participant0 the time coordinator. Participant0 also prints wall and CPU time of 1000 steps after 100 warm-up steps, which excludes participant creation, connection setup and service discovery. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Konrad Breitsprecher <Konrad.Breitsprecher@vector.com>
"Coordinated" is the lifecycle's OperationMode::Coordinated. Rename everything that referred to the time coordinator as "coordinated" or as a bare "coordinator": identifiers (SetTimeCoordinator, IsFollowingTimeCoordinator, _timeCoordinatorName), test names, log messages, docs and the changelog. The discovery key becomes TimeSyncIsTimeCoordinator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Konrad Breitsprecher <Konrad.Breitsprecher@vector.com>
Several participants may now set Experimental.TimeSynchronization.TimeCoordinator, for example because they share a configuration file. They are candidates; the time coordinator is chosen when all participants have replied after ServicesCreated (ServicesCreatedState, CallAfterAllParticipantsReplied). At that point every participant knows the TimeSyncService descriptors of all coordinated participants, so all choose the same one: the smallest name among the candidates with a coordinated lifecycle. Without such a candidate, a single autonomous candidate is chosen; several autonomous candidates abort, since there is no common barrier. A candidate discovered after the choice does not change it; if it would have won, the participants disagree and the simulation is aborted. A candidate that was not chosen leaves like any other participant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Konrad Breitsprecher <Konrad.Breitsprecher@vector.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Currently: Virtual time synchronization sends every NextSimTask to every other synchronized participant: O(N²) messages per step.
New: One participant can now be the time coordinator (
Experimental.TimeSynchronization.TimeCoordinator: true). Everyone else reports to it and waits for its grant: O(N) per step. The API is unchanged. The time coordinator is a normal participant with a TimeSyncService and a step handler.sequenceDiagram participant P1 participant C as Time coordinator participant P2 P1->>C: NextSimTask(t) P2->>C: NextSimTask(t) Note over C: T_min = min(next of all)<br/>grant only to participants at T_min C->>P1: grant(T_min) C->>P2: grant(T_min)No new wire message. The grant is a targeted
NextSimTaskmessage, soTimeConfigurationwaits for a single entry: the time coordinator's grant.Candidates are announced in service discovery (
TimeSyncIsTimeCoordinator=1, plusTimeSyncLifecycleIsCoordinated). Several participants may set the flag, e.g. from a shared config file. Exactly one is chosen, at the existing barrier after ServicesCreated, where every participant has received the service discovery of all others:A candidate that joins after the choice does not change it; if it would have won, the participants disagree and the simulation is aborted.
New capability
time-coordination. A synchronized peer without it aborts the simulation (same asautonomous-synchronous). So does a time coordinator that joins after the virtual time has started.If the time coordinator leaves while the simulation runs, the others log an error and stop advancing.
Evidence
SilKitDemoBenchmark, 1000 steps, with and without
--time-coordinator, 2–32 participants, over local domain sockets and over TCP, no messages besides time sync.Per 1000 steps. Release build, one Windows machine with 32 logical cores, all participants as threads in one process. Each point is measured over 1000 steps after 100 warm-up steps. Domain sockets: median of 5 runs in one process. TCP: median of 10 runs, each in a fresh process, in 10 interleaved passes; repeated runs inside one benchmark process were sometimes 4–5× slower after the first run (both modes), which made the first TCP sweep jumpy. CPU time is the processor time of all participants together. Domain sockets are SIL Kit's default between participants on the same machine; TCP is
EnableDomainSockets: false, as between machines.To reproduce:
SilKitDemoBenchmark --number-participants 32 --message-count 0 [--time-coordinator] [--configuration Demos/tools/Benchmark/DemoBenchmarkDomainSocketsOff.silkit.yaml](Release).Tests
Test_TimeCoordinator(new): lockstep, mixed step sizes (only the fast participant is granted), dynamic step boundary, no grant until all have reported, hop-on clamping, hop-off.Test_TimeSyncService: switching to the time coordinator, targeted reports, a peer's broadcast is ignored, a missing capability, an autonomous time coordinator. Several candidates: the smallest name is chosen (also when it is this participant), coordinated before autonomous, several autonomous-only abort, a losing candidate leaves without error, a late candidate does not change the choice.ITest_TimeCoordinator(new):Merge Danger
Door: two-way
Opt-in. Without
TimeCoordinator: trueon some participant, nothing changes on the wire. The only change visible to peers is the newtime-coordinationcapability.Blast Radius: small
Older SIL Kit versions can't take part in a simulation that has a time coordinator. That simulation aborts with an error naming the participant. Simulations without a time coordinator are unaffected. One mode change happens while the participant runs: switching from P2P to the time coordinator when it is discovered before time starts. That window is covered by unit tests, but not by a mixed-timing integration test.
Supersedes #460 (closed when its branch was renamed).
🤖 Generated with Claude Code