Latency Baseline Worker
125
Temporal scheduled workflow worker for:
latency_checkpoints.alerts.latency.ttft_regression on Kafka) and baseline tracking in Redis. [ Redis DDSketch Keys ] ────────── (Reads ttft & total latency sketches)
│
▼
[ latency-baseline-worker ] (Temporal Scheduled Workflow: LatencyBaselineWorkflow)
│ │
│ (F-L-11) │ (F-L-12)
│ Hourly │ After Checkpoint Write
│ │
▼ ▼
[ ClickHouse: latency_checkpoints ] [ Kafka: alerts.latency.ttft_regression ]
Upserts model checkpoints by day+hour Produces regression alert JSON messages
│
▼
[ Redis Baseline Keys ]
Stores computed baseline_p99_ttft values
F-L-11)(model, hour_of_day) pairs by scanning sketch:ttft:* keys in Redis.sketch:ttft:{model}:{hour_of_day}.sketch:total:{model}:{endpoint}:{hour_of_day}.p50, p95, p99) and sample_count (sketch.count) from each sketch.slo:errors:{model}:{endpoint}:{minute_bucket} for the entire hour.latency_checkpoints table.F-L-12)p99_ttft_ms history for the same model, endpoint, and hour of day over the last 7 days from ClickHouse.baseline_p99_ttft = median(last 7 values).baseline:p99_ttft:{model}:{endpoint}:{hour_of_day}).current_p99 > 2 * baseline_p99_ttft and sample_count >= 30:
alerts.latency.ttft_regression Kafka topic.F-L-13)sketch_missing_total{model, hour} without crashing (leaving a natural gap in ClickHouse).You can build the Docker image locally:
docker build -t chiefj/latency-baseline-worker:latest -f build/Dockerfile .
To launch the worker alongside dedicated postgres, clickhouse, redis, and temporal containers:
cd deploy/docker
docker compose up -d --build
The worker can be configured using the following environment variables:
| Environment Variable | Description | Default |
|---|---|---|
TEMPORAL_HOST | Temporal server address | localhost:7239 |
TEMPORAL_NAMESPACE | Temporal namespace | default |
TEMPORAL_TASK_QUEUE | Temporal task queue name | latency-baseline-tasks |
CLICKHOUSE_HOST | ClickHouse host | localhost |
CLICKHOUSE_PORT | ClickHouse HTTP port | 8129 |
CLICKHOUSE_USERNAME | ClickHouse username | default |
CLICKHOUSE_DATABASE | ClickHouse database | default |
REDIS_URL | Redis URL | redis://localhost:6389/0 |
KAFKA_BOOTSTRAP_SERVERS | Kafka bootstrap brokers | localhost:9099 |
HEALTH_PORT | HTTP port for the /health endpoint | 8003 |
To execute the complete unit test suite locally:
./scripts/test.sh
The worker includes a dedicated realtime Server-Sent Events (SSE) subsystem to push structured status updates during Activity execution to any configured SSE Gateway (preserving Last-Event-ID across connection drops).
realtime/ from Activities only; calling from Workflows breaks Temporal determinism.Within a Temporal activity:
from temporalio import activity
from realtime import ConnectionManager, SSEEvent, RetryConfig, RetryPolicy
@activity.defn
async def hourly_checkpoint(info) -> int:
act_info = activity.info()
# 1. Initialize Connection Manager
config = RetryConfig(max_attempts=3, initial_delay=1.0)
manager = ConnectionManager(policy=RetryPolicy(config))
# 2. Establish Connection
gateway_url = "http://localhost:8000/events"
await manager.connect(gateway_url)
# 3. Construct and Push Event
event = SSEEvent(
event_type="checkpoint_started",
data={"model": "gpt-4", "hour": 14},
workflow_id=act_info.workflow_id,
run_id=act_info.workflow_run_id,
attempt=act_info.attempt
)
manager.send_event(gateway_url, event)
# 4. Clean disconnect
manager.disconnect()
return 1
Content type
Image
Digest
sha256:a399f3bd3…
Size
233.9 MB
Last updated
3 months ago
docker pull chiefj/latency-baseline-worker