Skip to content

Commit 514af43

Browse files
authored
Merge b64cbe2 into a0b7ff9
2 parents a0b7ff9 + b64cbe2 commit 514af43

9 files changed

Lines changed: 257 additions & 55 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
__pycache__
22
.idea
3+
.venv
34
.vscode
45
allocator
56
bin/
67
coverage*out
78
test/allocator/allocator
89
test/infra/allocator/config.json
910
test/integration/integration-test
10-
venv

Makefile

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ INTEGRATION_COVERAGE_FILE := coverage.integration.out
1717
OVERALL_COVERAGE_FILE := coverage.overall.out
1818
COVERAGE_SUMMARY_FILE := coverage.out
1919
INTEGRATION_TEST_BIN := ./test/integration/integration-test
20+
ALLOCATOR_TEST_BIN := ./test/allocator/allocator
21+
22+
PYTHON_BIN ?= python3.14
23+
PYTHON_REQUIREMENTS_FILE := requirements.txt
24+
PYTHON_VENV_DIR ?= .venv
25+
PYTHON_VENV_BIN := $(PYTHON_VENV_DIR)/bin
26+
PYTHON_VENV_PYTHON := $(PYTHON_VENV_BIN)/python
27+
PYTHON_ANALYZE_DIR := ./test/allocator/analyze
28+
PYTHON_ANALYZE_SCRIPT := $(PYTHON_ANALYZE_DIR)/compare.py
2029

2130
.PHONY: help
2231
help:
@@ -30,22 +39,50 @@ install-lint:
3039
@mkdir -p "$(LOCAL_BIN)"
3140
@sh -s -- "$(LOCAL_BIN)" "$(GOLANGCI_LINT_VERSION)" "$(GOLANGCI_LINT_INSTALL_METHOD)" < scripts/install_golangci_lint.sh
3241

42+
.PHONY: python-venv
43+
python-venv:
44+
## Create venv with PYTHON_BIN and update pip.
45+
$(PYTHON_BIN) -m venv $(PYTHON_VENV_DIR)
46+
$(PYTHON_VENV_PYTHON) -m pip install --upgrade pip
47+
48+
.PHONY: python-deps
49+
python-deps: python-venv
50+
## Install Python dependencies from requirements file.
51+
$(PYTHON_VENV_PYTHON) -m pip install -r $(PYTHON_REQUIREMENTS_FILE)
52+
53+
.PHONY: python-check
54+
python-check: python-deps
55+
## Validate Python dependency graph and script syntax.
56+
$(PYTHON_VENV_PYTHON) -m pip check
57+
$(PYTHON_VENV_PYTHON) -m py_compile $(PYTHON_ANALYZE_DIR)/*.py
58+
59+
.PHONY: docker-check
60+
docker-check:
61+
## Ensure Docker daemon is reachable.
62+
@docker info >/dev/null 2>&1 || { \
63+
echo "error: Docker is required. Install Docker and make sure the daemon is running, then retry."; \
64+
exit 1; \
65+
}
66+
3367
.PHONY: generate
3468
generate:
3569
## Regenerate protobuf stubs for allocator schema.
3670
## Requires protoc to be installed: https://grpc.io/docs/protoc-installation/
3771
@command -v protoc >/dev/null || { \
38-
echo "error: protoc is required; install it first: https://grpc.io/docs/protoc-installation/"; \
72+
echo "error: protoc is required. Install it first: https://grpc.io/docs/protoc-installation/"; \
3973
exit 1; \
4074
}
4175
cd test/allocator/schema && ./generate.sh
4276

77+
.PHONY: allocator-build
78+
allocator-build:
79+
## Build allocator binary.
80+
go build -o $(ALLOCATOR_TEST_BIN) ./test/allocator
81+
4382
.PHONY: build
44-
build:
83+
build: allocator-build
4584
## Build all Go packages.
46-
## Also build allocator demo binary.
4785
go build ./...
48-
go build ./test/allocator
4986

5087
.PHONY: unit-test
5188
unit-test:
@@ -69,24 +106,32 @@ test: unit-test integration-test
69106
"$(OVERALL_COVERAGE_FILE)" \
70107
"$(COVERAGE_SUMMARY_FILE)"
71108

109+
.PHONY: lint-prepare
110+
lint-prepare: install-lint
111+
## Verify linter configuration.
112+
$(GOLANGCI_LINT) config verify
113+
72114
.PHONY: lint
73-
lint: install-lint
115+
lint: lint-prepare
74116
## Analyze code locally.
75117
## Use project-local golangci-lint from ./bin.
76-
## Verify linter config before checks.
77-
$(GOLANGCI_LINT) config verify
78118
$(GOLANGCI_LINT) run ./...
79119

80120
.PHONY: fix
81-
fix: install-lint
121+
fix: lint-prepare
82122
## Apply automatic source fixes.
83123
## Run go mod tidy, and golangci-lint --fix.
84124
go mod tidy
85-
$(GOLANGCI_LINT) config verify
86125
$(GOLANGCI_LINT) run --fix ./...
87126

127+
.PHONY: allocator-analyze
128+
allocator-analyze: allocator-build docker-check python-check
129+
## Run allocator docker benchmark and render plots.
130+
## Requires Docker daemon and test allocator binary.
131+
$(PYTHON_VENV_PYTHON) $(PYTHON_ANALYZE_SCRIPT)
132+
88133
.PHONY: clean
89134
clean:
90-
## Remove generated test and coverage artifacts.
91-
## Keep workspace clean between test runs.
92-
rm -f $(UNIT_COVERAGE_FILE) $(INTEGRATION_COVERAGE_FILE) $(OVERALL_COVERAGE_FILE) $(COVERAGE_SUMMARY_FILE) $(INTEGRATION_TEST_BIN)
135+
## Remove generated build, test, and Python cache artifacts.
136+
rm -f $(UNIT_COVERAGE_FILE) $(INTEGRATION_COVERAGE_FILE) $(OVERALL_COVERAGE_FILE) $(COVERAGE_SUMMARY_FILE) $(INTEGRATION_TEST_BIN) $(ALLOCATOR_TEST_BIN)
137+
rm -rf "$(PYTHON_ANALYZE_DIR)/__pycache__"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Go Reference](https://pkg.go.dev/badge/github.com/newcloudtechnologies/memlimiter.svg)](https://pkg.go.dev/github.com/newcloudtechnologies/memlimiter)
44
[![Go Report Card](https://goreportcard.com/badge/github.com/newcloudtechnologies/memlimiter)](https://goreportcard.com/report/github.com/newcloudtechnologies/memlimiter)
5-
![Coverage](https://img.shields.io/badge/Coverage-81.5%25-brightgreen)
5+
![Coverage](https://img.shields.io/badge/Coverage-81.7%25-brightgreen)
66
![CI](https://github.com/newcloudtechnologies/memlimiter/actions/workflows/CI.yml/badge.svg)
77

88
`memlimiter` helps a Go service avoid OOM by combining adaptive GC tuning and request throttling under memory pressure.
@@ -108,6 +108,8 @@ The MemLimiter comprises two main parts:
108108

109109
## Quick start guide
110110

111+
For command workflows and expected outputs, see [`make-workflows.md`](make-workflows.md).
112+
111113
### Services without `Cgo`
112114

113115
Refer to the [example service](test/allocator/server/server.go).

make-workflows.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Make Workflows (Linux / WSL)
2+
3+
This file describes how to use project `Makefile` targets and what output to expect.
4+
5+
## Prerequisites
6+
7+
- Go toolchain available in `PATH`.
8+
- Python `3.14` available as `python3.14` (or override with `PYTHON_BIN`).
9+
- Docker daemon running for allocator analysis.
10+
- `protoc` installed only if you run `make generate`.
11+
12+
## Quick Start
13+
14+
Run these once on a fresh checkout:
15+
16+
```bash
17+
make install-lint
18+
make python-check
19+
```
20+
21+
Expected results:
22+
23+
- `bin/golangci-lint` is installed.
24+
- `.venv` is created and dependencies are installed from `requirements.txt`.
25+
- `pip check` prints `No broken requirements found.`
26+
27+
## Daily Development Flow
28+
29+
### 1) Build
30+
31+
```bash
32+
make build
33+
```
34+
35+
What it does:
36+
37+
- Builds allocator demo binary: `test/allocator/allocator`.
38+
- Builds all Go packages in the repository.
39+
40+
### 2) Lint
41+
42+
```bash
43+
make lint
44+
```
45+
46+
What it does:
47+
48+
- Installs pinned `golangci-lint` if needed.
49+
- Verifies linter config.
50+
- Runs `golangci-lint run ./...`.
51+
52+
### 3) Auto-fix
53+
54+
```bash
55+
make fix
56+
```
57+
58+
What it does:
59+
60+
- Runs `go mod tidy`.
61+
- Runs `golangci-lint` with `--fix`.
62+
63+
### 4) Tests
64+
65+
```bash
66+
make unit-test
67+
make integration-test
68+
make test
69+
```
70+
71+
Expected artifacts:
72+
73+
- `coverage.unit.out`
74+
- `coverage.integration.out`
75+
- `coverage.overall.out`
76+
- `coverage.out` (human-readable summary)
77+
- `test/integration/integration-test` (integration test binary)
78+
79+
## Allocator Analysis Flow
80+
81+
Run:
82+
83+
```bash
84+
make allocator-analyze
85+
```
86+
87+
This target runs:
88+
89+
1. `make allocator-build`
90+
2. `make docker-check`
91+
3. `make python-check`
92+
4. Python benchmark/plot script: `test/allocator/analyze/compare.py`
93+
94+
Expected console signals:
95+
96+
- Lines like `>>> Start case: ...`
97+
- Progress logs from allocator perf client.
98+
99+
Expected output directory:
100+
101+
- `/tmp/allocator/allocator_<HHMMSS>/`
102+
103+
Expected generated files:
104+
105+
- `control_params.png`
106+
- `rss.png`
107+
- Per-case directories with:
108+
- `server_config.json`
109+
- `perf_config.json`
110+
- `tracker.csv`
111+
112+
## Utility Targets
113+
114+
- `make help` - print all available targets.
115+
- `make python-venv` - create `.venv` and upgrade `pip`.
116+
- `make python-deps` - install dependencies from `requirements.txt`.
117+
- `make python-check` - run `pip check` and Python syntax compile.
118+
- `make docker-check` - fail fast if Docker daemon is unavailable.
119+
- `make allocator-build` - build `test/allocator/allocator` only.
120+
- `make generate` - regenerate protobuf files for allocator schema.
121+
- `make lint-prepare` - install lint tools and verify lint config.
122+
- `make clean` - remove generated binaries, coverage files, and Python cache for analyzer scripts.
123+
124+
## Common Overrides
125+
126+
Use a different Python interpreter:
127+
128+
```bash
129+
make python-check PYTHON_BIN=python3.13
130+
```
131+
132+
Use a different virtual environment directory:
133+
134+
```bash
135+
make python-check PYTHON_VENV_DIR=.venv-local
136+
```

requirements.txt

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
certifi==2022.5.18.1
2-
charset-normalizer==2.0.12
3-
cycler==0.11.0
4-
docker==5.0.3
5-
fonttools==4.33.3
6-
humanize==4.1.0
7-
idna==3.3
8-
Jinja2==3.1.2
9-
kiwisolver==1.4.3
10-
MarkupSafe==2.1.1
11-
matplotlib==3.5.2
12-
numpy==1.22.4
13-
packaging==21.3
14-
pandas==1.4.2
15-
Pillow==9.1.1
16-
pyparsing==3.0.9
17-
python-dateutil==2.8.2
18-
pytz==2022.1
19-
requests==2.28.0
20-
six==1.16.0
21-
urllib3==1.26.9
22-
websocket-client==1.3.2
1+
certifi==2026.2.25
2+
charset-normalizer==3.4.7
3+
contourpy==1.3.3
4+
cycler==0.12.1
5+
docker==7.1.0
6+
fonttools==4.62.1
7+
humanize==4.15.0
8+
idna==3.11
9+
Jinja2==3.1.6
10+
kiwisolver==1.5.0
11+
MarkupSafe==3.0.3
12+
matplotlib==3.10.8
13+
numpy==2.4.4
14+
packaging==26.1
15+
pandas==3.0.2
16+
Pillow==12.2.0
17+
pyparsing==3.3.2
18+
python-dateutil==2.9.0.post0
19+
pytz==2026.1.post1
20+
requests==2.33.1
21+
six==1.17.0
22+
urllib3==2.6.3
23+
websocket-client==1.9.0

0 commit comments

Comments
 (0)