github sleep3r/mtproto.zig v0.8.0

latest releases: v1.15.2, v1.15.1, v1.15.0...
5 months ago

0.8.0 (2026-04-06)

🇷🇺 Release notes (RU)

Проблемы, которые решает этот релиз

  • При неоптимальных конфигурациях (завышенный max_connections, отсутствие rate-limit'а) могли не грузиться сториз и другие медиа — прокси уходил в перегрузку и не справлялся с relay-сессиями.
  • CPU мог очень жёстко утилизироваться из-за accept/close spin-loop'ов при насыщении пула соединений, особенно на 1 vCPU хостах.

Что добавлено и улучшено

  • Admission control с гистерезисом: при достижении ≥90% от max_connections прокси приостанавливает приём новых соединений на listen_fd и возобновляет только при падении ниже 80%. Это убирает spin-loop'ы при перегрузке.
  • Бюджет параллельных handshake'ов: одновременные handshake'и ограничены до 30% от max_connections. Сканеры и DPI-пробы больше не вытесняют активные relay-сессии.
  • Per-/24 subnet rate limiting: zero-allocation token bucket ограничивает новые соединения с одной /24 (IPv4) или /48 (IPv6) подсети — по умолчанию до 8 conn/sec. Настраивается через rate_limit_per_subnet.
  • Авто-клэмпинг max_connections по RAM: при старте прокси автоматически ограничивает max_connections безопасным значением на основе доступной оперативной памяти. Можно отключить через unsafe_override_limits = true.
  • Метрики деградации: 6 новых счётчиков в периодическом логе статистики:
    • cap — достигнут max_connections
    • sat — отброшено из-за saturation override
    • rate — сработал subnet rate limit
    • hs_budget — превышен лимит параллельных handshake'ов
    • hs_timeout — таймаут handshake'а
    • mp_fallback — fallback с MiddleProxy на direct

Важно

  • Если ранее у вас были проблемы с загрузкой сториз или высокой утилизацией CPU — обновление до 0.8.0 должно решить эти проблемы без ручного тюнинга конфигурации.
  • Авто-клэмпинг подберёт безопасные лимиты автоматически. Если вы уверены в своих значениях — используйте unsafe_override_limits = true.

🇬🇧 Release notes (EN)

Problems addressed in this release

  • With non-optimal configurations (inflated max_connections, no rate limiting), stories and other media could fail to load — the proxy would become overloaded and unable to sustain relay sessions.
  • CPU could spike extremely hard due to accept/close spin loops when the connection pool was saturated, especially on 1 vCPU hosts.

What's new and improved

  • Admission control with hysteresis: when active connections reach ≥90% of max_connections, the proxy pauses accepting new connections on listen_fd and resumes only when they drop below 80%. This eliminates spin loops under saturation.
  • Handshake inflight budget: concurrent handshakes are capped at 30% of max_connections. Scanner floods and DPI probes no longer evict active relay sessions.
  • Per-/24 subnet rate limiting: a zero-allocation token bucket limits new connections per /24 (IPv4) or /48 (IPv6) subnet — default: 8 conn/sec. Configurable via rate_limit_per_subnet.
  • Auto-clamping max_connections by RAM: at startup, the proxy automatically clamps max_connections to a RAM-safe estimate. Can be bypassed with unsafe_override_limits = true.
  • Degradation metrics: 6 new counters in the periodic stats log:
    • cap — reached max_connections
    • sat — dropped due to saturation override
    • rate — hit per-subnet rate limit
    • hs_budget — hit handshakes inflight limit
    • hs_timeout — handshake timeout reached
    • mp_fallback — MiddleProxy fallback to direct triggered

Important

  • If you previously experienced issues with stories not loading or high CPU utilization — upgrading to 0.8.0 should resolve these problems without manual config tuning.
  • Auto-clamping will pick safe limits automatically. If you are confident in your values, use unsafe_override_limits = true.

Recommended VPS presets (starting points)

Profile max_connections idle_timeout_sec handshake_timeout_sec rate_limit_per_subnet Notes
1 vCPU / 1 GB 512 120 15 8 Auto-clamped by default
2 vCPU / 2 GB 1024 120 15 8 Good for mixed traffic
4 vCPU / 4 GB 1536–2048 120 15 8 Raise gradually and monitor
8 vCPU / 8 GB 2048–3072 (per instance) 120 15 8 Prefer 2+ instances

Tuning guidance / Рекомендации по тюнингу

  • Start from the profile above, then increase max_connections in +15–25% steps.
  • Monitor: conn stats, reconnect/error rate, and sustained CPU.
  • If stories or media fail under load — your max_connections is likely too high for the host; let auto-clamp handle it or reduce manually.
  • If new clients intermittently fail under churn, reduce max_connections by ~20%.

Features

  • implement proxy resilience optimizations (#81) (71fb157)

This PR is managed by Release Please.

Don't miss a new mtproto.zig release

NewReleases is sending notifications on new releases.