POC 4 chủ đề performance Java back-end. Mỗi module chạy độc lập, Spring Boot 3.4 + Java 21.
| Module | Chủ đề | Port | Đọc |
|---|---|---|---|
| perf-poc-bloom | Bloom filter chặn cache penetration | 8081 | README |
| perf-poc-consistent-hash | Consistent hash ring sharding Redis | 8082 | README |
| perf-poc-hikari | Hikari pool tuning + p99 quan sát | 8083 | README |
| perf-poc-n-plus-one | N+1 detection (Hibernate Statistics) + fetch strategies | 8084 | README |
- JDK 21
- Maven 3.9+
- Docker Desktop (cho Postgres + Redis nodes)
docker compose up -d postgres redis-1 redis-2 redis-3Postgres tự tạo 3 database: poc_bloom, poc_hikari, poc_nplus1 (xem docker/init.sql).
Khi cần demo "thêm node" của consistent-hash:
docker compose --profile scale up -d redis-4mvn -pl perf-poc-bloom -am spring-boot:run
mvn -pl perf-poc-consistent-hash -am spring-boot:run
mvn -pl perf-poc-hikari -am spring-boot:run
mvn -pl perf-poc-n-plus-one -am spring-boot:runMở 4 terminal, mỗi terminal chạy 1 lệnh trên. Hoặc dùng tmux/Windows Terminal split.
mvn -DskipTests clean package| Chủ đề | Vấn đề giải quyết | Trade-off |
|---|---|---|
| Bloom filter | Cache miss tới DB cho key không tồn tại (penetration) | RAM cho bitset; false-positive 1% |
| Consistent hashing | hash(key) % N remap 100% khi thêm/bớt node |
Cần TreeMap + virtual nodes; phân phối có thể lệch nếu vnode thấp |
| Hikari tuning | Pool quá nhỏ → queue, p99 vọt; quá lớn → DB context-switch | Cần load test thật, không đoán bừa |
| N+1 detection | Lazy collection trong loop → N round-trip DB | DTO + JOIN FETCH / EntityGraph; cartesian product nếu nhiều collection |
perf-poc/
├── docker-compose.yml
├── docker/init.sql
├── pom.xml ← parent
├── perf-poc-bloom/
├── perf-poc-consistent-hash/
├── perf-poc-hikari/
└── perf-poc-n-plus-one/
- Cắm Prometheus + Grafana để xem hikari/n+1 metric thay vì curl /actuator/metrics
- Thêm JMeter / k6 script cho load test reproducible
- Thêm module Redis Cluster thay cho client-side consistent hashing (nếu team đã dùng Redis Cluster)
- Thêm module Caffeine + Redis 2-tier cache kèm singleflight để demo full cache-miss-storm prevention