-
Notifications
You must be signed in to change notification settings - Fork 1
test(core): CellScheduler scale probe — measure the O(n²) before refactoring #9131
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| module Zeta.Tests.FSharp.Algebra.CellSchedulerScaleTests | ||
|
|
||
| open Xunit | ||
| open System.Diagnostics | ||
| open Zeta.Core | ||
|
|
||
| // Scale probe (NOT a DST proof — a measurement to decide whether the deferred | ||
| // O(n^2)-queue perf refactor is actually earned). Wall-clock is informational | ||
| // only; the ASSERTIONS are correctness-at-scale (deterministic), not timing. | ||
|
|
||
| // Trivial int step: accumulate; a message carries a delta + forward targets. | ||
| type SMsg = { D: int; To: CellId list } | ||
| let private sstep (acc: int) (m: SMsg) : int * (CellId * SMsg) list = | ||
| acc + m.D, [ for t in m.To -> t, { D = m.D; To = [] } ] | ||
|
|
||
| [<Fact>] | ||
| let ``wide fan-out: one source to N sinks stays correct and fast`` () = | ||
| // Adversarial for the list-based Ready/inbox: one round delivers N messages. | ||
| let n = 2000 | ||
| let sinks = [ for i in 1 .. n -> sprintf "s%04d" i ] | ||
| let cells = ("src", 0) :: [ for s in sinks -> s, 0 ] | ||
| let seed = [ "src", { D = 0; To = sinks } ] // src fans a message to every sink | ||
| let sw = Stopwatch.StartNew() | ||
| match CellScheduler.runToQuiescence 1_000_000 sstep (CellScheduler.init cells seed) with | ||
| | Ok final -> | ||
| sw.Stop() | ||
| // every sink received exactly one message (D=0 ⇒ acc stays 0, but it RAN) | ||
| Assert.Equal(n + 1, Map.count final) | ||
| // correctness at scale: all sinks present and processed | ||
| Assert.All(sinks, fun s -> Assert.True(Map.containsKey s final)) | ||
| printfn "[scale] wide fan-out N=%d: %d ms" n sw.ElapsedMilliseconds | ||
| | Error e -> failwith e | ||
|
|
||
| [<Fact>] | ||
| let ``deep chain: a delta threads N cells and arrives intact`` () = | ||
| // A linear pipeline of N relays; one delta flows end to end over N rounds. | ||
| let n = 2000 | ||
| let ids = [ for i in 0 .. n - 1 -> sprintf "c%04d" i ] | ||
| let cells = [ for id in ids -> id, 0 ] | ||
| // Each cell forwards +1 to the numerically-next cell id (encoded by convention), | ||
| // so one seeded delta threads the whole chain, one hop per round. | ||
| let seedChain = [ "c0000", { D = 1; To = [ "c0001" ] } ] | ||
| let chainStep (acc: int) (m: SMsg) : int * (CellId * SMsg) list = | ||
| acc + m.D, | ||
| [ for t in m.To do | ||
| let idx = System.Int32.Parse(t.Substring 1) | ||
| let nextTo = if idx + 1 < n then [ sprintf "c%04d" (idx + 1) ] else [] | ||
| yield t, { D = 1; To = nextTo } ] | ||
| let sw = Stopwatch.StartNew() | ||
| match CellScheduler.runToQuiescence 1_000_000 chainStep (CellScheduler.init cells seedChain) with | ||
| | Ok final -> | ||
| sw.Stop() | ||
| // the delta reached the last cell (every cell on the path accumulated 1) | ||
| Assert.Equal(1, Map.find (sprintf "c%04d" (n - 1)) final) | ||
| Assert.Equal(1, Map.find "c0001" final) | ||
| printfn "[scale] deep chain N=%d: %d ms" n sw.ElapsedMilliseconds | ||
| | Error e -> failwith e | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this scale case seeds
D = 0and sends only one message to each sink, the later count/contains assertions would still pass if the scheduler dropped all emitted sink messages after initializing the cells. It also never exercises the documented same-inboxq @ [msg]cliff, since no cell receives more than one message; a fan-in/aggregator workload or nonzero sink assertion is needed before using this probe to justify deferring the queue refactor.Useful? React with 👍 / 👎.