Skip to content

Task 2-2: Monitor Queue Depth - Prize Allocation & Invitation

Phase: 2 - Performance Priority: Medium Depends on: Không có Reference: docs/BountyHunter-Backend/details/feature-matching-matchmaking/SPEC.md

Background

Matchmaking enqueue vào prize-allocation queues và invitation queue. Nếu lag cao, match được tạo nhưng room creation bị delay.

Tasks

DI Note: - BatchQueueMonitorService cần inject JmsTemplate hoặc ActiveMQ Session để query queue depth (hoặc dùng JMX/management endpoint của broker). Xác nhận pattern checkQueueLag() đã dùng gì trong service hiện tại trước khi thêm entry mới. - JMSPrizeAllocationListener@Component với @JmsListener. Thêm logging tại đây không cần inject thêm — dùng existing LOGGER.

  • [ ] Thêm monitoring cho invitation queue trong BatchQueueMonitorService:
    // Trong BatchQueueMonitorService.monitorQueues() (hoặc scheduled method):
    checkQueueLag("queue-invitation", 20);  // alert nếu depth > 20
    
  • Xác nhận method signature checkQueueLag(String queueName, int threshold) tồn tại trước khi gọi

  • [ ] Log average match-to-room-creation latency (khoảng thời gian từ khi MATCH_FOUND tới khi ROOM_CREATED):

    // Trong prize allocation listener, sau khi tạo room:
    // Giả sử matchTime được lưu trong message hoặc MatchRecord:
    LOGGER.info("[MATCHING_LATENCY] match_to_room_ms={} settingId={}",
        Duration.between(matchTime, Instant.now()).toMillis(), settingId);
    

  • Xác định nơi lưu matchTime (có thể là field trong message payload hoặc Redis key)

Verification / Acceptance Criteria

  • [ ] BatchQueueMonitorService có entry cho queue-invitation với threshold 20
  • [ ] Khi queue-invitation depth > 20 → log WARN (hoặc alert) xuất hiện
  • [ ] Log [MATCHING_LATENCY] match_to_room_ms=X xuất hiện trong JMSPrizeAllocationListener mỗi khi room được tạo
  • [ ] Latency log có đủ context: settingId (và optional prizeId) để phân tích per game mode

Files to Modify

  • batch/src/main/java/com/figpop/batch/service/BatchQueueMonitorService.java
  • batch/jms/prize_allocation/JMSPrizeAllocationListener.java