Skip to content

Commit cb67517

Browse files
authored
Merge pull request #826 from renuka-fernando/policy-engine-bench
Add policy engine benchmark tests
2 parents 6299e5c + 3a23d5f commit cb67517

4 files changed

Lines changed: 1664 additions & 4 deletions

File tree

gateway/policy-engine/README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,37 @@ cd tests/contract
124124
go test ./...
125125
```
126126

127-
## License
127+
## Benchmarking
128128

129-
[Add License Information]
129+
Performance benchmarks are located in the following packages:
130130

131-
## Contributing
131+
- `internal/kernel/` - ExtProc Process() lifecycle benchmarks
132+
- `internal/executor/` - Policy chain execution benchmarks
133+
- `internal/pkg/cel/` - CEL expression evaluation benchmarks
132134

133-
See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines.
135+
### Running Benchmarks
136+
137+
```bash
138+
# Run all benchmarks with memory allocation stats
139+
go test -bench=. -benchmem -count=5 ./internal/kernel/ -run=^$
140+
go test -bench=. -benchmem -count=5 ./internal/executor/ -run=^$
141+
go test -bench=. -benchmem -count=5 ./internal/pkg/cel/ -run=^$
142+
143+
# Run specific benchmark
144+
go test -bench=BenchmarkProcess/NoPolicies -benchmem -count=5 ./internal/kernel/ -run=^$
145+
go test -bench=BenchmarkProcess/1Policy -benchmem -count=5 ./internal/kernel/ -run=^$
146+
147+
# Generate CPU profile for optimization
148+
go test -bench=BenchmarkProcess -benchmem -cpuprofile=cpu.prof ./internal/kernel/ -run=^$
149+
go tool pprof -http=:8080 cpu.prof
150+
151+
# Generate memory profile
152+
go test -bench=BenchmarkProcess -benchmem -memprofile=mem.prof ./internal/kernel/ -run=^$
153+
go tool pprof -http=:8080 mem.prof
154+
155+
# Compare benchmarks (requires benchstat: go install golang.org/x/perf/cmd/benchstat@latest)
156+
go test -bench=. -benchmem -count=10 ./internal/kernel/ -run=^$ > old.txt
157+
# Make changes...
158+
go test -bench=. -benchmem -count=10 ./internal/kernel/ -run=^$ > new.txt
159+
benchstat old.txt new.txt
160+
```

0 commit comments

Comments
 (0)