Commit d03d3b6
authored
feat: Add top-level Flow Controller (#1525)
* feat(flowcontrol): Refactor FlowRegistry contracts
This commit refactors some of the core Flow Control contracts to improve
clarity and better align with their intended roles. The goal is to
create a more intuitive and robust interface for the upcoming top-level
FlowController.
Key changes include:
- The `FlowRegistryClient` interface is renamed to
`FlowRegistryDataPlane` to more accurately reflect its role in the
high-throughput request path.
- The `FlowRegistryAdmin` interface is renamed to `FlowRegistryObserver`
to clarify its read-only, observational nature.
- The `ActiveFlowConnection.Shards()` method is renamed to
`ActiveFlowConnection.ActiveShards()` to make it explicit that it
returns only active, schedulable shards. This removes ambiguity for
the distributor logic.
- `ShardStats` is enriched with `ID` and `IsActive` fields, providing
consumers with more context about the shard's state at the time the
snapshot was taken.
- The registry implementation has been updated to match these new
contract definitions.
* refactor: Adapt ShardProcessor to a worker role
This commit refactors the `ShardProcessor` to function as a stateful
worker managed by a higher-level supervisor. This is a preparatory step
for the introduction of the new top-level `FlowController`.
The public API of the processor is changed from a direct `Enqueue`
method to a more sophisticated, channel-based submission model with
`Submit` (non-blocking) and `SubmitOrBlock` (blocking). This decouples
the producer from the processor's main loop, enabling better
backpressure signals and higher throughput.
Key changes include:
- Introduction of `Submit` and `SubmitOrBlock` for asynchronous request
handoff.
- `FlowItem`'s finalization logic is improved to be more robust and
channel-based.
- Error handling within the dispatch cycle is refactored (no logic
change) to be more clear about how it promotes work conservation by
isolating failures to a single priority band.
* feat: Introduce the FlowController supervisor
This commit introduces the `FlowController`, a high-throughput, sharded
supervisor that orchestrates a pool of stateful `ShardProcessor`
workers. This new component is the central processing engine of the Flow
Control system, implementing a "supervisor-worker" pattern.
Key features of the `FlowController` include:
- Supervisor-Worker Architecture: Acts as a stateless supervisor,
managing the lifecycle of stateful `ShardProcessor` workers. It
includes a reconciliation loop to garbage-collect workers for stale
shards.
- Flow-Aware Load Balancing: Implements a "Join-Shortest-Queue-by-Bytes"
(JSQ-Bytes) algorithm to distribute incoming requests to the
least-loaded worker, promoting emergent fairness.
- Synchronous API: Exposes a blocking `EnqueueAndWait` method, which
simplifies client integration (e.g., with Envoy `ext_proc`) and
provides direct backpressure.
- Lazy Worker Initialization: Workers are created on-demand when a shard
shard first becomes active to conserve resources and reduce contention
on the hot path.
- Configuration: A new `Config` object allows for tuning parameters like
TTLs, buffer sizes, and reconciliation intervals.
* docs: Update comments to align with FlowController
This commit updates documentation and code comments across various
framework components to align with the concepts and architecture
introduced by the `FlowController`.
Key changes include:
- FCFS Policy: Clarified the distinction between "logical" and
"physical" enqueue time and the behavioral trade-offs when pairing
with different queue capabilities.
- ListQueue: Expanded the documentation to explain its role as a
high-performance, approximate FCFS queue in the context of the
`FlowController`'s retry mechanics.
- Request Types: Refined the comments for `QueueItemAccessor` to be more
precise about the meaning of `EnqueueTime`.
* refactor Simplify controller Lifecycle
This commit refactors the `FlowController` to simplify its startup and
shutdown lifecycle, making it more robust and easier to reason about.
It also incorporates several smaller improvements based on reviewer
feedback.
The primary change addresses a complex lifecycle implementation that
used an `atomic.Bool` (`isRunning`) and a `ready` channel to manage
state.
Key changes:
- **Simplified Lifecycle:** The controller's lifecycle is now tied
directly to a `context` passed into `NewFlowController`. The `Run`
method has been unexported, and the main `run` loop is started as a
goroutine from the constructor. This eliminates the `ready` channel
and `isRunning` flag in addition to simplifying the interface for
callers.
- **Robust Worker Creation:** The `getOrStartWorker` logic has been
improved to ensure that in a race to create a worker, the "losing"
goroutine correctly cleans up its resources and does not start a
redundant processor. This fixes a bug where the losing worker would
evict all items from its queues on shutdown which were shared
instances with the winning worker resulting in premature request
finalization.
- **Comment Reduction:** The extensive explanatory comments in
`distributeRequest` have been condensed to be more concise while
retaining the essential details of the algorithm.
- **Minor Cleanups:**
- The initial, unnecessary call to `reconcileProcessors()` at
startup has been removed.
- Error messages have been clarified (e.g., "acquire lease" instead
of "establish connection").
- A typed error for nil requests was replaced with a standard
`errors.New`.1 parent 9266b5e commit d03d3b6
File tree
22 files changed
+2043
-650
lines changed- pkg/epp/flowcontrol
- contracts
- controller
- internal
- framework/plugins
- policies/intraflow/dispatch/fcfs
- queue/listqueue
- registry
- types
22 files changed
+2043
-650
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
| 51 | + | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 64 | + | |
| 65 | + | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
| |||
90 | 89 | | |
91 | 90 | | |
92 | 91 | | |
93 | | - | |
94 | | - | |
95 | | - | |
| 92 | + | |
| 93 | + | |
96 | 94 | | |
97 | 95 | | |
98 | 96 | | |
| |||
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
142 | | - | |
| 140 | + | |
143 | 141 | | |
144 | 142 | | |
145 | 143 | | |
| |||
162 | 160 | | |
163 | 161 | | |
164 | 162 | | |
| 163 | + | |
165 | 164 | | |
166 | 165 | | |
167 | 166 | | |
| |||
173 | 172 | | |
174 | 173 | | |
175 | 174 | | |
176 | | - | |
| 175 | + | |
| 176 | + | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
178 | 184 | | |
179 | 185 | | |
180 | 186 | | |
| |||
192 | 198 | | |
193 | 199 | | |
194 | 200 | | |
| 201 | + | |
195 | 202 | | |
196 | 203 | | |
197 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
0 commit comments