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: -
BatchQueueMonitorServicecần injectJmsTemplatehoặc ActiveMQSessionđể query queue depth (hoặc dùng JMX/management endpoint của broker). Xác nhận patterncheckQueueLag()đã dùng gì trong service hiện tại trước khi thêm entry mới. -JMSPrizeAllocationListenerlà@Componentvới@JmsListener. Thêm logging tại đây không cần inject thêm — dùng existingLOGGER.
- [ ] 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_FOUNDtới khiROOM_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
- [ ]
BatchQueueMonitorServicecó entry choqueue-invitationvới threshold 20 - [ ] Khi
queue-invitationdepth > 20 → log WARN (hoặc alert) xuất hiện - [ ] Log
[MATCHING_LATENCY] match_to_room_ms=Xxuất hiện trongJMSPrizeAllocationListenermỗi khi room được tạo - [ ] Latency log có đủ context:
settingId(và optionalprizeId) để phân tích per game mode
Files to Modify
batch/src/main/java/com/figpop/batch/service/BatchQueueMonitorService.javabatch/jms/prize_allocation/JMSPrizeAllocationListener.java