Task 2-1: Tune Matchmaking Scheduler Interval
Phase: 2 - Performance Priority: Medium Module:
batchDepends on: Không có Reference: docs/BountyHunter-Backend/details/feature-matching-matchmaking/SPEC.md
Background
MatchMakingForAllGameModeConfig chạy theo fixed interval. Interval hiện tại chưa được calibrate theo traffic thực tế. Quá nhanh → CPU waste; quá chậm → user chờ lâu.
Tasks
DI Note:
MatchMakingForAllGameModeConfiglà@Configurationclass với@Scheduledmethod. Để dùng@Scheduled, cần đảm bảo@EnableSchedulingtồn tại (thường ở main@SpringBootApplicationclass củabatchmodule). Config value inject qua@Valueannotation trực tiếp trên field hoặc constructor param.
- [ ] Xác nhận interval hiện tại: grep
MatchMakingForAllGameModeConfigđể tìm@Scheduledannotation và giá trị interval - [ ] Thu thập data từ production logs: average queue size per tick, average wait time từ
JOIN_QUEUEtớiMATCH_FOUND - [ ] Đề xuất interval tối ưu dựa trên data (thường 1-3 giây là hợp lý cho matchmaking)
- [ ] Externalize interval thành config property (không hardcode):
# application-common.yaml (batch module) matchmaking: scheduler: fixed-delay: 2000 # 2 seconds — điều chỉnh dựa trên traffic data// MatchMakingForAllGameModeConfig.java @Scheduled(fixedDelayString = "${matchmaking.scheduler.fixed-delay:2000}") public void runMatchmaking() { ... } - [ ] Verify không overlap: dùng
fixedDelay(không phảifixedRate) — next tick chỉ start sau khi current tick xong + delay
Verification / Acceptance Criteria
- [ ]
matchmaking.scheduler.fixed-delayxuất hiện trongapplication-common.yaml - [ ]
@Scheduled(fixedDelayString = ...)thay vì hardcodedfixedDelay = 2000 - [ ] Thay đổi config value → scheduler interval thay đổi mà không cần rebuild
- [ ] Không có overlap: khi 1 matchmaking run chậm (> interval) → next run chờ run hiện tại hoàn thành
- [ ] Log interval mới với lý do chọn (dựa trên traffic data)
Files to Modify
batch/job/matchmaking/MatchMakingForAllGameModeConfig.javabatch/src/main/resources/application-common.yaml