Skip to content

Task 2-1: Tune Matchmaking Scheduler Interval

Phase: 2 - Performance Priority: Medium Module: batch Depends 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: MatchMakingForAllGameModeConfig@Configuration class với @Scheduled method. Để dùng @Scheduled, cần đảm bảo @EnableScheduling tồn tại (thường ở main @SpringBootApplication class của batch module). Config value inject qua @Value annotation trực tiếp trên field hoặc constructor param.

  • [ ] Xác nhận interval hiện tại: grep MatchMakingForAllGameModeConfig để tìm @Scheduled annotation và giá trị interval
  • [ ] Thu thập data từ production logs: average queue size per tick, average wait time từ JOIN_QUEUE tới MATCH_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ải fixedRate) — next tick chỉ start sau khi current tick xong + delay

Verification / Acceptance Criteria

  • [ ] matchmaking.scheduler.fixed-delay xuất hiện trong application-common.yaml
  • [ ] @Scheduled(fixedDelayString = ...) thay vì hardcoded fixedDelay = 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.java
  • batch/src/main/resources/application-common.yaml