Skip to content

Commit f3ef090

Browse files
authored
Cache (#99)
* Update to v0.12.3 - Implemented SPF caching in demand placement to optimize shortest path computations, reducing redundant calculations for cacheable policies (ECMP, WCMP, TE_WCMP_UNLIM). * Enhance TrafficDemand handling and context caching
1 parent e9c0436 commit f3ef090

22 files changed

Lines changed: 2115 additions & 406 deletions

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.12.3] - 2025-12-11
9+
10+
### Changed
11+
12+
- **SPF caching in demand placement**: `demand_placement_analysis()` caches SPF results by (source, policy_preset) for ECMP, WCMP, and TE_WCMP_UNLIM policies; TE policies recompute when capacity constraints require alternate paths
13+
- **MSD AnalysisContext caching**: `MaximumSupportedDemand` builds `AnalysisContext` once and reuses it across all binary search probes
14+
15+
### Fixed
16+
17+
- **TrafficDemand ID preservation**: Fixed context caching with `mode: combine` by ensuring `TrafficDemand.id` is preserved through serialization; pseudo node names now remain consistent across context build and analysis
18+
819
## [0.12.2] - 2025-12-08
920

1021
### Fixed

docs/reference/api-full.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Quick links:
1212
- [CLI Reference](cli.md)
1313
- [DSL Reference](dsl.md)
1414

15-
Generated from source code on: December 07, 2025 at 00:13 UTC
15+
Generated from source code on: December 11, 2025 at 23:43 UTC
1616

1717
Modules auto-discovered: 44
1818

@@ -460,12 +460,12 @@ Attributes:
460460
demand: Total demand volume.
461461
demand_placed: Portion of this demand placed so far.
462462
flow_policy_config: Policy preset (FlowPolicyPreset enum) used to build
463-
a `FlowPolicy` if ``flow_policy`` is not provided.
463+
a `FlowPolicy`` if ``flow_policy`` is not provided.
464464
flow_policy: Concrete policy instance. If set, it overrides
465465
``flow_policy_config``.
466466
mode: Expansion mode, ``"combine"`` or ``"pairwise"``.
467467
attrs: Arbitrary user metadata.
468-
id: Unique identifier assigned at initialization.
468+
id: Unique identifier. Auto-generated if empty or not provided.
469469

470470
**Attributes:**
471471

@@ -1238,6 +1238,9 @@ placeable for a given matrix. Stores results under `data` as:
12381238
- `base_demands`: serialized base demand specs
12391239
- `probes`: bracket/bisect evaluations with feasibility
12401240

1241+
Performance: AnalysisContext is built once at search start and reused across
1242+
all binary search probes. Only demand volumes change per probe.
1243+
12411244
### MaximumSupportedDemand
12421245

12431246
MaximumSupportedDemand(name: 'str' = '', seed: 'Optional[int]' = None, _seed_source: 'str' = '', matrix_name: 'str' = 'default', acceptance_rule: 'str' = 'hard', alpha_start: 'float' = 1.0, growth_factor: 'float' = 2.0, alpha_min: 'float' = 1e-06, alpha_max: 'float' = 1000000000.0, resolution: 'float' = 0.01, max_bracket_iters: 'int' = 32, max_bisect_iters: 'int' = 32, seeds_per_alpha: 'int' = 1, placement_rounds: 'int | str' = 'auto')
@@ -2345,6 +2348,10 @@ with FailureManager's caching and multiprocessing systems.
23452348
Graph caching enables efficient repeated analysis with different exclusion
23462349
sets by building the graph once and using O(|excluded|) masks for exclusions.
23472350

2351+
SPF caching enables efficient demand placement by computing shortest paths once
2352+
per unique source node rather than once per demand. For networks with many demands
2353+
sharing the same sources, this can reduce SPF computations by an order of magnitude.
2354+
23482355
### build_demand_context(network: "'Network'", demands_config: 'list[dict[str, Any]]') -> 'AnalysisContext'
23492356

23502357
Build an AnalysisContext for repeated demand placement analysis.
@@ -2383,8 +2390,15 @@ This function:
23832390

23842391
1. Builds Core infrastructure (graph, algorithms, flow_graph) or uses cached
23852392
2. Expands demands into concrete (src, dst, volume) tuples
2386-
3. Places each demand using Core's FlowPolicy with exclusion masks
2387-
4. Aggregates results into FlowIterationResult
2393+
3. Places each demand using SPF caching for cacheable policies
2394+
4. Falls back to FlowPolicy for complex multi-flow policies
2395+
5. Aggregates results into FlowIterationResult
2396+
2397+
SPF Caching Optimization:
2398+
For cacheable policies (ECMP, WCMP, TE_WCMP_UNLIM), SPF results are
2399+
cached by source node. This reduces SPF computations from O(demands)
2400+
to O(unique_sources), typically a 5-10x reduction for workloads with
2401+
many demands sharing the same sources.
23882402

23892403
Args:
23902404
network: Network instance.
@@ -2509,7 +2523,7 @@ Attributes:
25092523
volume: Traffic volume to place.
25102524
priority: Priority class (lower is higher priority).
25112525
policy_preset: FlowPolicy configuration preset.
2512-
demand_id: Parent TrafficDemand ID (for tracking).
2526+
demand_id: Parent TrafficDemand ID for tracking.
25132527

25142528
**Attributes:**
25152529

docs/reference/design.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ Managers handle scenario dynamics and prepare inputs for algorithmic steps.
654654
- Deterministic expansion: source/sink node lists sorted alphabetically; no randomization
655655
- Supports `combine` mode (aggregate via pseudo nodes) and `pairwise` mode (individual (src,dst) pairs with volume split)
656656
- Demands sorted by ascending priority before placement (lower value = higher priority)
657-
- Placement handled by Core's FlowPolicy with configurable presets (ECMP, WCMP, TE modes)
657+
- Placement uses SPF caching for simple policies (ECMP, WCMP, TE_WCMP_UNLIM), FlowPolicy for complex multi-flow policies
658658
- Non-mutating: operates on Core flow graphs with exclusions; Network remains unmodified
659659

660660
**Failure Manager** (`ngraph.exec.failure.manager`): Applies a `FailurePolicy` to compute exclusion sets and runs analyses with those exclusions.
@@ -737,6 +737,16 @@ For Monte Carlo analysis with many failure iterations, graph construction is amo
737737

738738
This optimization is critical for performance: graph construction involves Python processing, NumPy array creation, and C++ object initialization. Building the graph once eliminates this overhead from the per-iteration critical path, enabling the GIL-releasing C++ algorithms to execute with minimal Python overhead.
739739

740+
**SPF Caching for Demand Placement:**
741+
742+
For demand placement with cacheable policies (ECMP, WCMP, TE_WCMP_UNLIM), SPF results are cached by (source_node, policy_preset):
743+
744+
- Initial SPF computed once per unique source; subsequent demands from the same source reuse the cached DAG
745+
- For TE policies, DAG is recomputed when capacity constraints require alternate paths
746+
- Complex multi-flow policies (TE_ECMP_16_LSP, TE_ECMP_UP_TO_256_LSP) use FlowPolicy directly
747+
748+
This reduces SPF computations from O(demands) to O(unique_sources) for workloads where many demands share the same source nodes.
749+
740750
**Monte Carlo Deduplication:**
741751

742752
FailureManager collapses identical failure patterns into single executions. Runtime

ngraph/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__all__ = ["__version__"]
44

5-
__version__ = "0.12.2"
5+
__version__ = "0.12.3"

0 commit comments

Comments
 (0)