Implementation:Tensorflow Serving servable state h
| Knowledge Sources | |
|---|---|
| Domains | Model Serving, Core Framework |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
ServableState defines the semantic lifecycle state of a servable as maintained by a Manager, including its identifier, state enum, and health status.
Description
The ServableState struct represents a snapshot of a servable's recent state within a Manager. It is typically published on an EventBus to enable monitoring and observability. Since managers and event bus implementations can have multiple threads, the state represents a recent snapshot rather than a real-time guarantee.
The ManagerState enum defines five lifecycle stages that transition only in one direction (from higher to lower on the list):
- kStart - The manager is tracking the servable but has not initiated any action.
- kLoading - The manager has decided to load the servable and is about to invoke the loader.
- kAvailable - The servable is loaded and available for serving (reported after availability).
- kUnloading - The manager is about to make the servable unavailable (reported before unavailability).
- kEnd - The servable has completed its lifecycle, either successfully or with an error.
The health field captures any errors that occurred during the servable's lifecycle, regardless of whether they originated in a Source, SourceAdapter, Loader, or Manager.
Usage
Use ServableState to observe and react to servable lifecycle transitions. It is consumed by ServableStateMonitor and published via EventBus<ServableState>. It is a read-only observation type; managers produce it internally.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File: tensorflow_serving/core/servable_state.h
- Lines: 1-113
Signature
struct ServableState {
ServableId id;
enum class ManagerState : int {
kStart,
kLoading,
kAvailable,
kUnloading,
kEnd,
};
static string ManagerStateString(ManagerState state);
ManagerState manager_state;
Status health;
string DebugString() const;
};
bool operator==(const ServableState& a, const ServableState& b);
bool operator!=(const ServableState& a, const ServableState& b);
std::ostream& operator<<(std::ostream& os, const ServableState& state);
Import
#include "tensorflow_serving/core/servable_state.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| id | ServableId | Yes | The identifier of the servable whose state is represented |
| manager_state | ManagerState | Yes | The lifecycle state enum value |
| health | Status | Yes | OK if healthy; otherwise the error encountered during the servable's lifecycle |
Outputs
| Name | Type | Description |
|---|---|---|
| DebugString() | string | Human-readable representation including id, state, and health |
| ManagerStateString() | string | String representation of the ManagerState enum (e.g., "Loading", "Available") |
Usage Examples
Observing Servable State via EventBus
#include "tensorflow_serving/core/servable_state.h"
using namespace tensorflow::serving;
// Constructing a state snapshot
ServableState state;
state.id = {"my_model", 1};
state.manager_state = ServableState::ManagerState::kAvailable;
state.health = Status();
LOG(INFO) << "State: " << state;
// Outputs: id: {name: my_model version: 1} manager_state: Available health: OK
Checking State Transitions
void OnStateChange(const ServableState& state) {
if (state.manager_state == ServableState::ManagerState::kAvailable) {
LOG(INFO) << "Servable " << state.id << " is now available.";
}
if (state.manager_state == ServableState::ManagerState::kEnd &&
!state.health.ok()) {
LOG(ERROR) << "Servable " << state.id << " ended with error: "
<< state.health;
}
}