Skip to content

timesync: time coordinator, O(N) instead of O(N²) sync traffic - #460

Closed
KonradBreitsprecherBkd wants to merge 3 commits into
mainfrom
dev_central-time-master
Closed

KonradBreitsprecherBkd wants to merge 3 commits into
mainfrom
dev_central-time-master

Conversation

@KonradBreitsprecherBkd

@KonradBreitsprecherBkd KonradBreitsprecherBkd commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Naming: always time coordinator, so it isn't confused with the coordinated lifecycle (OperationMode::Coordinated).

Virtual time synchronization sends every NextSimTask to every other synchronized participant: O(N²) messages per step. 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)
Loading
participant: advances iff own next == T_min      (same rule as P2P: own next <= all others)
time coordinator: on report / hop-on / hop-off
  T_min = min over all participants (below the current grant: clamped to it)
  if T_min increased: send grant {T_min, boundary - T_min} to participants at T_min
                      (boundary = earliest step start/end after T_min, for dynamic step sizes)
  • No new wire message. The grant is a targeted NextSimTask, so TimeConfiguration waits for a single entry: the time coordinator's grant.
  • Announced in service discovery (TimeSyncIsTimeCoordinator=1). Participants start following the time coordinator when they discover it.
  • New capability time-coordination. A synchronized peer without it aborts the simulation (same as autonomous-synchronous). So does a second time coordinator, or 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.
SilKit/source/services/orchestration/
├── TimeCoordinator.{hpp,cpp}   # new: grant logic, no I/O
├── TimeSyncService.cpp         # routing: P2P / report to the time coordinator / be the time coordinator
└── TimeConfiguration.cpp       # follow the time coordinator, hop-on from the grant

Evidence

Before / After: the same 1000 steps, with and without --time-coordinator, 2–32 participants, no messages besides time sync.

image
Participants P2P wall Time coordinator wall P2P CPU Time coordinator CPU
2 11.8 ms 29.3 ms 31 ms 31 ms
8 69.0 ms 62.8 ms 391 ms 172 ms
16 277 ms 185 ms 3,547 ms 531 ms
32 778 ms 405 ms 18,234 ms 1,500 ms

Release build, one Windows machine with 32 logical cores, all participants as threads in one process. Each point is the median of 5 runs, measured over 1000 steps after 100 warm-up steps. CPU time is the processor time of all participants together.

  • CPU per step grows ~N² for P2P and ~N with the time coordinator: 12× less at 32 participants.
  • Wall time: 1.9× faster at 32. Below ~8 participants the time coordinator is slower: each step needs a report and a grant, two hops instead of one broadcast. On one machine, P2P's extra work runs in parallel on spare cores, so wall time understates the difference that separate machines would see.

To reproduce: SilKitDemoBenchmark --number-participants 32 --message-count 0 [--time-coordinator] (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, a second time coordinator, an autonomous time coordinator.
  • ITest_TimeCoordinator (new):
    • Runs with a time coordinator execute exactly the same steps as P2P runs (5 participants, step sizes 1/2/3/5/7 ms).
    • A causality check: no participant starts a step before all others have completed up to that time.
    • Async handlers, dynamic step sizes, and an autonomous hop-on at 50 ms / hop-off at 100 ms.
    • Stable over 10 repeats.
  • Full unit (707) and integration (122) suites pass on Windows (Debug).

Merge Danger

Door: two-way

Opt-in. Without TimeCoordinator: true on some participant, nothing changes on the wire. The only change visible to peers is the new time-coordination capability.

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.

🤖 Generated with Claude Code

…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>
@KonradBreitsprecherBkd KonradBreitsprecherBkd added the status: wip Work in progress. Not ready for review yet. label Nov 25, 2026
"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>
@KonradBreitsprecherBkd KonradBreitsprecherBkd changed the title timesync: central time coordinator, O(N) instead of O(N²) sync traffic timesync: time coordinator, O(N) instead of O(N²) sync traffic Nov 25, 2026
@KonradBreitsprecherBkd
KonradBreitsprecherBkd deleted the dev_central-time-master branch November 25, 2026 14:10
@KonradBreitsprecherBkd

Copy link
Copy Markdown
Contributor Author

Superseded by #461: this PR was closed automatically when its branch was renamed to dev_central-time-coordinator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: wip Work in progress. Not ready for review yet.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant