[BE-35] 다중 인스턴스 host rate throttle

작업 내용 (설계 의도)

변경 사항

TDD의 HostRequestThrottleGateway와 MySQL 구현을 추가하고 SourceRequestExecutor를 이를 통해 호출한다. 기존 host/path/page-size/User-Agent 검증을 유지하되 host별 next_allowed_at 예약은 DB 원자 갱신으로 바꾼다. wait는 DB transaction 밖에서만 수행한다. 롤백은 v2 dispatcher OFF 시에도 기존 executor 동작이 유지되도록 adapter를 하위 호환으로 둔다.

의존

  • DBA host throttle 테이블 migration

다이어그램

처리 흐름

sequenceDiagram
    participant E as RequestExecutor
    participant T as HostThrottle
    participant DB as MySQL
    E->>T: reserve(host, delay)
    T->>DB: lock/update next_allowed_at
    DB-->>T: notBefore
    T-->>E: notBefore
    E->>E: wait outside transaction

클래스 의존

flowchart LR
    SourceRequestExecutor --> HostRequestThrottleGateway
    PersistentHostThrottle -.-> HostRequestThrottleGateway
    PersistentHostThrottle --> MySQL

테스트 케이스

  • 같은 host를 두 executor가 동시에 예약해도 요청 가능 시각은 최소 지연만큼 직렬화된다.
  • 서로 다른 host 예약은 서로 대기시키지 않는다.
  • 예약 후 wait 구간에는 DB transaction이 열려 있지 않다.
  • 허용되지 않은 host/path와 초과 page-size 요청은 throttle 이전에 거부된다.