Skip to content

Commit a865e07

Browse files
committed
added Dockerfile for the batch pod. added miniredis for testing. added Makefile support for batch exec.
1 parent 55a52c1 commit a865e07

File tree

6 files changed

+72
-11
lines changed

6 files changed

+72
-11
lines changed

Dockerfile.batch

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Build Stage: using Go 1.24 image
2+
FROM quay.io/projectquay/golang:1.24 AS builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
ARG COMMIT_SHA=unknown
6+
ARG BUILD_REF
7+
8+
WORKDIR /workspace
9+
# Copy the Go Modules manifests
10+
COPY go.mod go.mod
11+
COPY go.sum go.sum
12+
# cache deps before building and copying source so that we don't need to re-download as much
13+
# and so that source changes don't invalidate our downloaded layer
14+
RUN go mod download
15+
16+
# Copy the go source
17+
COPY cmd/batch/ cmd/batch/
18+
COPY pkg/batch/ pkg/batch/
19+
COPY pkg/metrics/ pkg/metrics/
20+
COPY pkg/common pkg/common
21+
22+
# Build
23+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
24+
# was called. For example, if we call make image-build in a local env which has the Apple Silicon M1 SO
25+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
26+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
27+
ENV CGO_ENABLED=0
28+
ENV GOOS=${TARGETOS:-linux}
29+
ENV GOARCH=${TARGETARCH}
30+
RUN go build -a -o bin/batch \
31+
-ldflags="-X github.com/llm-d/llm-d-inference-scheduler/pkg/batch/version.CommitSHA=${COMMIT_SHA} -X github.com/llm-d/llm-d-inference-scheduler/pkg/batch/version.BuildRef=${BUILD_REF}" \
32+
cmd/batch/main.go
33+
34+
FROM registry.access.redhat.com/ubi9/ubi-micro:latest
35+
WORKDIR /
36+
COPY --from=builder /workspace/bin/batch /app/batch
37+
USER 65532:65532
38+
39+
ENTRYPOINT ["/app/batch"]

Makefile

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ SIDECAR_TAG ?= dev
1919
export SIDECAR_TAG
2020
SIDECAR_IMAGE_TAG_BASE ?= $(IMAGE_REGISTRY)/$(SIDECAR_IMAGE_NAME)
2121
export SIDECAR_IMAGE ?= $(SIDECAR_IMAGE_TAG_BASE):$(SIDECAR_TAG)
22+
BATCH_TAG ?= dev
23+
export BATCH_TAG
24+
BATCH_IMAGE_TAG_BASE ?= $(IMAGE_REGISTRY)/batch
25+
export BATCH_IMAGE ?= $(BATCH_IMAGE_TAG_BASE):$(BATCH_TAG)
26+
2227
NAMESPACE ?= hc4ai-operator
2328
VLLM_SIMULATOR_TAG ?= v0.6.1
2429
export VLLM_SIMULATOR_TAG
@@ -94,16 +99,24 @@ CGO_LDFLAGS := $(PYTHON_LDFLAGS) $(PYTHON_LIBS) '-L$(shell pwd)/lib' -ltokenizer
9499
# Internal variables for generic targets
95100
epp_IMAGE = $(EPP_IMAGE)
96101
sidecar_IMAGE = $(SIDECAR_IMAGE)
102+
batch_IMAGE = $(BATCH_IMAGE)
97103
epp_NAME = epp
98104
sidecar_NAME = $(SIDECAR_NAME)
105+
batch_NAME = batch
99106
epp_LDFLAGS = -ldflags="$(LDFLAGS)"
100107
sidecar_LDFLAGS =
108+
batch_LDFLAGS = -ldflags="$(LDFLAGS)"
101109
epp_CGO_CFLAGS = "${CGO_CFLAGS}"
102110
sidecar_CGO_CFLAGS =
111+
batch_CGO_CFLAGS = "${CGO_CFLAGS}"
103112
epp_CGO_LDFLAGS = "${CGO_LDFLAGS}"
104113
sidecar_CGO_LDFLAGS =
114+
batch_CGO_LDFLAGS = "${CGO_LDFLAGS}"
105115
epp_TEST_FILES = go list ./... | grep -v /test/ | grep -v ./pkg/sidecar/
106116
sidecar_TEST_FILES = go list ./pkg/sidecar/...
117+
batch_TEST_FILES = go list ./... | grep -v /test/ | grep -v ./pkg/batch/
118+
119+
107120

108121
.PHONY: help
109122
help: ## Print help
@@ -142,7 +155,7 @@ format: ## Format Go source files
142155
test: test-unit test-e2e ## Run unit tests and e2e tests
143156

144157
.PHONY: test-unit
145-
test-unit: test-unit-epp test-unit-sidecar
158+
test-unit: test-unit-epp test-unit-sidecar test-unit-batch
146159

147160
.PHONY: test-unit-%
148161
test-unit-%: download-tokenizer install-dependencies ## Run unit tests
@@ -173,7 +186,7 @@ lint: check-golangci-lint check-typos ## Run lint
173186
##@ Build
174187

175188
.PHONY: build
176-
build: build-epp build-sidecar ## Build the project
189+
build: build-epp build-sidecar build-batch ## Build the project
177190

178191
.PHONY: build-%
179192
build-%: check-go install-dependencies download-tokenizer ## Build the project
@@ -183,7 +196,7 @@ build-%: check-go install-dependencies download-tokenizer ## Build the project
183196
##@ Container Build/Push
184197

185198
.PHONY: image-build
186-
image-build: image-build-epp image-build-sidecar ## Build Docker image
199+
image-build: image-build-epp image-build-sidecar image-build-batch ## Build Docker image
187200

188201
.PHONY: image-build-%
189202
image-build-%: check-container-tool ## Build Docker image ## Build Docker image using $(CONTAINER_RUNTIME)
@@ -197,7 +210,7 @@ image-build-%: check-container-tool ## Build Docker image ## Build Docker image
197210
-t $($*_IMAGE) -f Dockerfile.$* .
198211

199212
.PHONY: image-push
200-
image-push: image-push-epp image-push-sidecar ## Push container images to registry
213+
image-push: image-push-epp image-push-sidecar image-push-batch ## Push container images to registry
201214

202215
.PHONY: image-push-%
203216
image-push-%: check-container-tool ## Push container image to registry

cmd/batch/runner/runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ func (r *Runner) Run(ctx context.Context) error {
6363
}
6464
var policy batch.RequestPolicy = batch.NewRandomRobinPolicy()
6565

66-
var impl batch.Flow = redis.NewRedisMQFlow("localhost:6379")
66+
var impl batch.Flow = redis.NewRedisMQFlow("localhost:16379")
6767
requestChannel := policy.MergeRequestChannels(impl.RequestChannels()).Channel
6868
for w := 1; w <= *concurrency; w++ {
6969
go batch.Worker(ctx, *endpoint, httpClient, requestChannel, impl.RetryChannel(), impl.ResultChannel())
7070
}
7171

7272
impl.Start(ctx)
73-
73+
<-ctx.Done()
7474
return nil
7575
}
7676

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/onsi/gomega v1.38.2
1616
github.com/openai/openai-go v1.12.0
1717
github.com/prometheus/client_golang v1.23.2
18+
github.com/alicebob/miniredis/v2 v2.35.0
1819
github.com/stretchr/testify v1.11.1
1920
golang.org/x/sync v0.18.0
2021
google.golang.org/grpc v1.76.0
@@ -93,6 +94,7 @@ require (
9394
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
9495
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
9596
github.com/x448/float16 v0.8.4 // indirect
97+
github.com/yuin/gopher-lua v1.1.1 // indirect
9698
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
9799
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
98100
go.opentelemetry.io/otel v1.38.0 // indirect

pkg/batch/GUIDE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Batch Processor - User Guide
2+
3+
The batch processor helps in workflows where you have requests that are latency tolerant. I.e., SLOs in minutes/ hours instead of seconds.
4+
5+
The batch processor pulls requests from a message queue (or several MQs according to a policy), sends to the Inference Gateway (IGW) and retries if necessary (e.g., message was shedded).
6+
7+
![Batch Processor - Redis architecture](/docs/images/batch_processor_redis_architecture.png "BP - Redis")

test/integration/redisimpl_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import (
66
"testing"
77
"time"
88

9+
"github.com/alicebob/miniredis/v2"
910
"github.com/llm-d/llm-d-inference-scheduler/pkg/batch"
1011
"github.com/llm-d/llm-d-inference-scheduler/pkg/batch/redis"
1112
)
1213

13-
const (
14-
redisURL = "localhost:6379"
15-
)
16-
1714
func TestRedisImpl(t *testing.T) {
15+
s := miniredis.RunT(t)
16+
rAddr := s.Host() + ":" + s.Port()
17+
1818
ctx := context.Background()
19-
flow := redis.NewRedisMQFlow(redisURL)
19+
flow := redis.NewRedisMQFlow(rAddr)
2020
flow.Start(ctx)
2121

2222
flow.RetryChannel() <- batch.RetryMessage{

0 commit comments

Comments
 (0)