Skip to content

First sync: pace history calls to what Telegram allows, not a fixed 3 s #133

Closed

Description

@neoromantic

A first sync of a real account (about 2,600 chats with sync on, about 800,000 messages) took about 11 hours of active time with 0.8.0. Measured from sync_jobs and status.jsonl:

  • 9,986 messages.getHistory calls, one every ~4.1 s (0.25 calls/s). A call took 204 ms at the median (p90 507 ms), writing a page ~10 ms.
  • About 92% of the active time was the pause between jobs. The 3 s interJobDelayMs becomes ~3.8 s because a job is picked on the main loop's next 1 s tick.
  • Not a single FLOOD_WAIT on getHistory the whole time.

A probe on a test account (getHistory, 100 per page, one public channel, closed loop) got its first FLOOD_WAIT at 1 call/s after 70–100 calls, with short waits (3–15 s) that grew under pressure; through them it sustained 0.85–0.95 calls/s. 0.7 calls/s ran 150 s with none. Two chats in parallel brought no gain. Whether the counter is per chat, per method or per account is unknown.

Proposed:

  1. Measure the pause from when a job starts, or pick jobs on their own timer, so the 3 s really is 3 s (×1.2).
  2. Adaptive pacing while history is pending: start at ~0.7 calls/s, speed up after clean runs up to a cap (~0.8–0.9/s), halve on a FLOOD_WAIT, and go back to the calm interval once the first pass is done. Expected: the first sync in ~3–4 hours of active time instead of ~11.
  3. Show the current pace and an estimate in tg status (with Sync jobs drop the senders and the message count of each history page #126's counts).

Parallel jobs per account and takeout sessions only after measurements. Done when a test with an injected clock and fake FLOOD_WAITs covers speed-up and back-off, a one-to-two-hour run on the test account shows the rate and no long FLOOD_WAIT, and docs/rate-limiting.md and docs/sync-strategy.md describe the pacing. Related: #126.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions