fix periodic-check request queue throughput bottleneck
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 12s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 12s
The bot's request_queue.py 4s FIFO gate wasn't protecting against Lichess's rate limiter — that's already handled downstream in LichessWebServices/ rate_limiter.py (0.2s, shared across all callers of our stats service). The bot-side gate only paced calls to our own local service, and since it awaited each request to full completion before dequeuing the next, real dispatch gaps were max(4s, previous request's duration) — with 454 tracked gamer/user pairs, any burst (e.g. after a restart) piled into the queue and took 10-20+ minutes to drain. Replace it with a paced-dispatch + bounded-concurrency design: a hard 2s floor between dispatches (still never lets 2+ requests through in that window), decoupled from completion time, with up to 10 requests actually in flight at once via a semaphore. Doesn't touch the real Lichess-facing rate limit at all. Also add deterministic per-(user,gamer) checkpoint jitter: previously every pair sharing the same period_minutes re-locked onto the same wall-clock phase on every restart (backlog collapse snaps period_end_approx to `now` for everyone overdue at once), recreating the pileup each time. Jitter is stable across restarts (crc32-based, not Python's salted hash()) and capped well under the 2h stale-backlog threshold. Small startup stagger added too, purely cosmetic smoothing on top of the jitter fix.
This commit is contained in:
parent
ad6daf2918
commit
8080921141
3 changed files with 159 additions and 79 deletions
|
|
@ -10,8 +10,25 @@ ADMINPANEL_TELEGRAM_BOT_TOKEN = os.getenv("ADMINPANEL_TELEGRAM_BOT_TOKEN")
|
|||
# Lichess API Configuration
|
||||
LICHESS_API_BASE_URL = "https://lichess.org/api"
|
||||
LICHESS_STATS_API_BASE_URL = "http://localhost:8002" # Host port for stats API when bot runs with host networking
|
||||
# Минимальная задержка (сек) между запросами к Lichess в очереди мониторинга (избежание бана)
|
||||
LICHESS_REQUEST_QUEUE_MIN_DELAY = 4.0
|
||||
|
||||
# Пейсинг очереди запросов к НАШЕМУ ЖЕ локальному stats-сервису (LICHESS_STATS_API_BASE_URL).
|
||||
# Это НЕ защита от рейт-лимитера Lichess — та уже есть ниже по стеку, в
|
||||
# LichessWebServices/rate_limiter.py (0.2s, единственный process-wide инстанс,
|
||||
# применяется перед каждым реальным вызовом lichess.org, общий для всех клиентов
|
||||
# stats-сервиса). Эти числа можно свободно менять — они не увеличивают нагрузку на Lichess.
|
||||
LICHESS_REQUEST_QUEUE_MIN_DISPATCH_INTERVAL = 2.0 # сек между диспетчами запросов (жёсткий пол)
|
||||
LICHESS_REQUEST_QUEUE_MAX_CONCURRENT = 10 # макс. запросов к stats-сервису одновременно; 1 = откат к строго последовательному режиму
|
||||
|
||||
# Джиттер чекпоинтов периодических проверок: не даёт парам (user, gamer) с одинаковым
|
||||
# period_minutes синхронизироваться на один и тот же wall-clock момент при рестарте бота
|
||||
# (см. periodic_check в bot.py). Потолок держим далеко ниже STALE_BACKLOG_THRESHOLD (2ч),
|
||||
# чтобы не задевать логику подавления уведомлений по устаревшему бэклогу.
|
||||
PERIODIC_CHECKPOINT_JITTER_FRACTION = 0.10
|
||||
PERIODIC_CHECKPOINT_JITTER_MAX_SECONDS = 300
|
||||
|
||||
# Разброс старта периодических задач при запуске бота, чтобы не бить по SQLite
|
||||
# синхронно за один тик event loop при большом числе отслеживаемых игроков.
|
||||
PERIODIC_STARTUP_STAGGER_MAX_SECONDS = 30
|
||||
|
||||
# Database Configuration
|
||||
def _resolve_database_path() -> str:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue