Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect Telegram users after startup lazily to avoid slow startup times #698

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Half-Shot
Copy link
Contributor

Fixes #697
Fixes #316

This PR refactors the way connections are made to Telegram slightly which hopefully doesn't hurt smaller bridges, but actively improves the startup time of larger bridges. Previously, the Telegram bridge would attempt to connect all puppeted users on startup to Telegram and only become "ready" once everyone had been connected (or an attempt had been made). However, this becomes a challenge at scale in the 100s of clients because these connections can each take some time which causes traffic to be delayed and ultimately leads to a worse experience.

This PR instead starts connections to Telegram after the bridge has finished it's startup seqeuence. This is also backed by a semaphore to prevent more than N connections to be attempted at once, this is by design as it allows active Matrix users to "jump ahead" in the queue by calling ensure_started when handling a Matrix message and therefore get connected before they would usually via the queue.

The semaphore lock is important, as by default all users attempt to connect at once and thus lock in a waiting state until the bridge has connected them. This would mean that calls to ensure_started would fail as a connection would be in progress.

Thus, this solution hopefully ensures that active users get connected quickly without slowing down traffic processing.

Myself and @tadzik have tested this PR on our side, so we believe it has legs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants