Skip to content

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

Open
KonradBreitsprecherBkd wants to merge 4 commits into
mainfrom
dev_central-time-coordinator
Open

KonradBreitsprecherBkd wants to merge 4 commits into
mainfrom
dev_central-time-coordinator

Conversation

@KonradBreitsprecherBkd

@KonradBreitsprecherBkd KonradBreitsprecherBkd commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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)
Loading
  • No new wire message. The grant is a targeted NextSimTask message, so TimeConfiguration waits for a single entry: the time coordinator's grant.

  • Candidates are announced in service discovery (TimeSyncIsTimeCoordinator=1, plus TimeSyncLifecycleIsCoordinated). 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:

    ServicesCreatedState::ServicesCreated
      CallAfterAllParticipantsReplied          # all TimeSyncService descriptors have arrived
        ResolveTimeCoordinator
          coordinated candidates?  -> smallest name     # same set on every participant
          else one autonomous      -> that one
          else several autonomous  -> abort              # no common barrier, no robust choice
      -> CommunicationInitializing
    

    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 as autonomous-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.

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

SilKitDemoBenchmark, 1000 steps, with and without --time-coordinator, 2–32 participants, over local domain sockets and over TCP, no messages besides time sync.

image
Participants Transport P2P wall Time coordinator wall P2P CPU Time coordinator CPU Gain wall / CPU
2 domain sockets 11.8 ms 29.3 ms 31 ms 31 ms 0.4× / 1.0×
2 TCP 29.8 ms 58.5 ms 47 ms 63 ms 0.5× / 0.8×
8 domain sockets 69.0 ms 62.8 ms 391 ms 172 ms 1.1× / 2.3×
8 TCP 274 ms 170 ms 1,633 ms 320 ms 1.6× / 5.1×
16 domain sockets 277 ms 185 ms 3,547 ms 531 ms 1.5× / 6.7×
16 TCP 681 ms 354 ms 9,297 ms 891 ms 1.9× / 10.4×
32 domain sockets 778 ms 405 ms 18,234 ms 1,500 ms 1.9× / 12×
32 TCP 2,069 ms 583 ms 52,672 ms 1,453 ms 3.5× / 36×

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.

  • Break-even at about 8 participants over domain sockets and about 6 over TCP. From there on, the time coordinator is faster in wall time. Below that it is slower, because each step needs a report and a grant: two hops instead of one broadcast.
  • CPU per step grows ~N² for P2P and ~N with the time coordinator: 12× less at 32 participants over domain sockets, 36× less over TCP. TCP makes each message more expensive, which hurts P2P's ~N² messages most.
  • Wall time: 1.9× faster at 32 participants over domain sockets, 3.5× over TCP. On one machine part of that comes from P2P's CPU load: over TCP at 32 participants, P2P keeps about 25 of the 32 cores busy. On dedicated machines, per participant, the time coordinator handles all 2N messages of a step itself, so expect a smaller wall-time gain there. The main gain on separate machines is the sync load per participant: about 2 messages per step instead of about 2(N−1).

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):
    • 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.
    • Three candidates (P2, P4, P5, P5 created first): P2 is chosen, P4 and P5 follow, the steps equal P2P. Hop-on/hop-off with two candidates: the joiner follows the chosen one.
    • 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.

Supersedes #460 (closed when its branch was renamed).

🤖 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>
"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

No deployments
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