-
Notifications
You must be signed in to change notification settings - Fork 19
Data Layer proposal. #49
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
Open
Mohammad-nassar10
wants to merge
7
commits into
llm-d:main
Choose a base branch
from
Mohammad-nassar10:data-layer-proposal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1c080ee
Data Layer proposal.
Mohammad-nassar10 26dcb31
Merge branch 'llm-d:main' into data-layer-proposal
Mohammad-nassar10 929402d
Fix comments.
Mohammad-nassar10 f2a2a44
Update the proposal.
Mohammad-nassar10 adcec7b
Fix lint error.
Mohammad-nassar10 90626ec
Update proposal.
Mohammad-nassar10 6d804fa
Align with datastore changes.
Mohammad-nassar10 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| # Proposal: Data Layer | ||
|
|
||
| ## Summary | ||
|
|
||
| Introduce an **Async Data Layer** — a background observation pipeline that runs | ||
| **outside the critical request path**. It collects runtime events fired by the producer | ||
| (currently `server.go`), buffers them off the hot path, and dispatches them to registered | ||
| `Extractor`s that compute aggregates and write them to the DataStore for the Model Selector. | ||
|
|
||
| ## Goal | ||
|
|
||
| Track runtime information about inference requests to help make better routing decisions — | ||
| for example, which model has the least in-flight requests or the lowest average latency. | ||
| This information is read by the Model Selector (Filter / Score / Pick) when choosing | ||
| where to route each request. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - **Non-blocking on the critical path** - data collection must add zero latency to request handling. | ||
| - **Multiple independent extractors** - different metrics must be computable independently without coupling to each other. | ||
| - **Extensible** - adding a new metric or event type must not require changes to existing extractors or the producer. | ||
| - **Off the plugin pipeline** - the data layer is a background concern; it must not participate in the per-request plugin chain. | ||
|
|
||
| ## Proposal | ||
|
|
||
| ### Architecture | ||
|
|
||
| ```mermaid | ||
| flowchart TD | ||
| P["Producer\n(server.go)"] | ||
| PP["Plugin Pipeline\nFilter → Score → Pick"] | ||
| NS["NotificationSource\nchan Event (buffered)"] | ||
| EL["event loop"] | ||
| ExtA["InflightRequestsExtractor"] | ||
| ExtB["LatencyExtractor\n(future)"] | ||
| DS[("Datastore\npkg/datastore")] | ||
| MS["Model Selector\n(InflightRequestsScorer)"] | ||
|
|
||
| P -->|"Notify(event) ~ns"| NS | ||
| P --> PP | ||
| NS --> EL | ||
| EL -->|"one event at a time"| ExtA | ||
| EL -->|"one event at a time"| ExtB | ||
| ExtA --> DS | ||
| ExtB --> DS | ||
| DS --> MS | ||
| PP -->|reads| MS | ||
| ``` | ||
|
|
||
| The **producer** (currently `server.go`) fires an `Event` on each request and response — | ||
| a non-blocking channel write (~ns). The `NotificationSource` buffers it. A background | ||
| event loop reads each event from the channel as it arrives and fans it out to all registered | ||
| `Extractor`s. Each extractor switches on `Event.Type` and handles what it understands, | ||
| ignoring the rest. | ||
|
|
||
| ### Types (`pkg/framework/datalayer/`) | ||
|
|
||
| ```go | ||
| type DataSource interface { | ||
| framework.Plugin // TypedName() TypedName | ||
| Start(ctx context.Context) error | ||
| // Stop signals the component to shut down and blocks until it has fully stopped. | ||
| Stop() | ||
| } | ||
|
|
||
| // Event is the uniform carrier of all data layer events. | ||
| // Type identifies what happened; Payload holds the event-specific data. | ||
| type Event struct { | ||
| Type EventType | ||
| Payload any | ||
| } | ||
|
|
||
| // EventNotifier is the narrow interface the producer uses to fire events. | ||
| // Keeping it separate lets the server depend only on Notify, not on lifecycle | ||
| // or extractor registration. | ||
| type EventNotifier interface { | ||
| Notify(e Event) | ||
| } | ||
|
|
||
| // NotificationSource buffers events off the hot path and dispatches | ||
| // each event to registered Extractors as it arrives. | ||
| type NotificationSource interface { | ||
|
Mohammad-nassar10 marked this conversation as resolved.
|
||
| DataSource | ||
| EventNotifier | ||
| // RegisterExtractor adds an extractor after construction. | ||
| // Extractors known at construction time can be passed to New directly. | ||
| RegisterExtractor(e Extractor) | ||
| } | ||
|
|
||
| // Extractor processes a batch of Events. It does not manage its own goroutines. | ||
| type Extractor interface { | ||
|
Mohammad-nassar10 marked this conversation as resolved.
|
||
| framework.Plugin | ||
| Extract(ctx context.Context, events []Event) error | ||
| } | ||
| ``` | ||
|
|
||
| See [Appendix](#appendix) for payload struct definitions and a full extractor example. | ||
|
|
||
| ### DataStore injection | ||
|
|
||
| The `DataStore` is passed directly to each extractor's constructor. This keeps the | ||
| `NotificationSource` a pure event dispatcher with no knowledge of storage, and avoids routing the store through `framework.Handle`. | ||
|
|
||
| The concrete implementation lives in `pkg/datastore/inmemory`, separate from the | ||
| `pkg/datastore.Datastore` interface, to make room for future backends (e.g. Redis): | ||
|
|
||
| ```go | ||
| ds := inmemory.NewDatastore() | ||
| extractor := inflightrequests.NewInflightRequestsExtractor(ds) | ||
| ``` | ||
|
|
||
| ### Registration (`runner.go`) | ||
|
|
||
| ```go | ||
| ds := inmemory.NewDatastore() | ||
| src, err := notificationsource.New("default", inflightrequests.NewInflightRequestsExtractor(ds)) | ||
| if err != nil { ... } | ||
| if err := src.Start(ctx); err != nil { ... } | ||
| // TODO: pass src to the producer so it can call src.Notify(...) | ||
| ``` | ||
|
|
||
| **Next:** define a configuration story for data layer plugins (NotificationSource, extractors) | ||
| consistent with how model-selector plugins are configured via CLI flags. | ||
|
|
||
| ## Future | ||
|
|
||
| - **LatencyExtractor** - handles `ResponseEventType`; per-model avg latency; owns `"pool-latency"` attribute | ||
| - **PollingDataSource** - polls inference pool `/metrics` on a ticker; same `Extractor` interface | ||
|
|
||
| ## Implementation Steps | ||
|
|
||
| 1. Add `DataSource`, `DataStore`, `EventNotifier`, `Event`, `NotificationSource`, `Extractor`, payload types to `pkg/framework/datalayer/` | ||
| 2. Implement `NotificationSource` (buffered channel + event loop) in `pkg/plugins/datalayer/notificationsource/` | ||
| 3. Implement `InflightRequestsExtractor` in `pkg/plugins/datalayer/inflightrequests/` | ||
| 4. Implement `InflightRequestsScorer` in `pkg/framework/modelselector/scorer/inflightrequests/` | ||
| 5. Wire DataStore + extractor + NotificationSource in `runner.go` | ||
| 6. Add `src.Notify(...)` calls to the producer alongside existing pipeline dispatch | ||
| 7. Config-driven registration of data layer plugins | ||
|
|
||
| --- | ||
|
|
||
| ## Appendix | ||
|
|
||
| ### Payload types | ||
|
|
||
| ```go | ||
| // package datalayer (pkg/framework/datalayer/) | ||
|
|
||
| // RequestPayload is the Payload for RequestEventType. | ||
| // Carries the already-parsed request — no re-parsing needed. | ||
| type RequestPayload struct { | ||
| Request *framework.InferenceRequest | ||
| } | ||
|
|
||
| // ResponsePayload is the Payload for ResponseEventType. | ||
| // Duration is computed by the producer and passed directly. | ||
| // All response body fields are accessible via Response.Body. | ||
| type ResponsePayload struct { | ||
| Request *framework.InferenceRequest | ||
| Response *framework.InferenceResponse | ||
| Duration time.Duration | ||
| } | ||
| ``` | ||
|
|
||
| ### Extractor definitions | ||
|
|
||
| #### `InflightRequestsExtractor` — owns `"inflight-requests"` (`pkg/plugins/datalayer/inflightrequests`) | ||
|
|
||
| | | | | ||
| |---|---| | ||
| | Handles | `RequestEventType` (increment), `ResponseEventType` (decrement) | | ||
| | Reads | `model`, `max_tokens` from `Request.Body` | | ||
| | State | `map[string]InflightRequestsCount` — in-flight counters per model | | ||
| | Writes | `InflightRequestsCount{Requests int64, Tokens int64}` per model | | ||
|
|
||
| ```go | ||
| type InflightRequestsCount struct { | ||
| Requests int64 | ||
| Tokens int64 // sum of max_tokens across in-flight requests | ||
| } | ||
| ``` | ||
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.
Uh oh!
There was an error while loading. Please reload this page.