Skip to content

fix: connect backoff mechanism #1354

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

Merged
merged 10 commits into from
May 5, 2025
Merged

fix: connect backoff mechanism #1354

merged 10 commits into from
May 5, 2025

Conversation

filipecabaco
Copy link
Member

What kind of change does this PR introduce?

Simple mechanism to prevent to many Connect processes from trying to startup in the same node.

Copy link

vercel bot commented Apr 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
realtime-demo ⬜️ Ignored (Inspect) Visit Preview May 3, 2025 10:25am

@filipecabaco filipecabaco force-pushed the fix/selective-migration-running branch from 860074e to dae86db Compare April 29, 2025 20:46
@filipecabaco filipecabaco requested review from edgurgel and a team April 29, 2025 21:56
@filipecabaco
Copy link
Member Author

@supabase/dashbit it would be very useful to get some feedback from your side on lib/realtime/rate_counter/rate_counter.ex and lib/realtime/gen_counter/gen_counter.ex 🙏

Copy link

@jonatanklosko jonatanklosko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @filipecabaco!

I looked at the counter modules, I have two notes:

  1. I noticed you use :erlang.phash2/1:

    id = :erlang.phash2(term)

    This function isn't the best at generating unique values. It has 2^32 possible return values, which is relatively low for hashing. A typical usage of phash would be to deterministically assign value to a partition (in fact, phash2 accepts a second argument N, to cap the range). It is fair to expect collisions are very much possible.

    What you could do is lookup by phash2, but handle a case where there are multiple results and filter those based on the exact keys. That said, as long as you use simple terms (I see you use a tuple with two atoms and id), it's most likely fine to not hash altogether.

  2. Is there any reason GenCounter starts a process? It seems to me you only really use the registry to store and lookup keys, but not the process itself. If that's the case, what you actually want is to store the counters in an ETS table (which is exactly what Registry uses under the hood).

@filipecabaco filipecabaco force-pushed the fix/selective-migration-running branch 14 times, most recently from 271eb6e to 7a96230 Compare April 30, 2025 18:00
Base automatically changed from fix/selective-migration-running to main April 30, 2025 18:39
Simple mechanism to prevent to many Connect processes from trying to startup in the same node.
@coveralls
Copy link

coveralls commented Apr 30, 2025

Coverage Status

coverage: 82.276% (+0.5%) from 81.779%
when pulling c02c23b on fix/connect-backoff
into e2275cd on main.

@filipecabaco filipecabaco force-pushed the fix/connect-backoff branch 7 times, most recently from 565e79f to 220b379 Compare May 2, 2025 15:40
@filipecabaco filipecabaco force-pushed the fix/connect-backoff branch from 220b379 to 228e4d1 Compare May 2, 2025 16:49
@filipecabaco filipecabaco merged commit fe70a4f into main May 5, 2025
6 of 7 checks passed
@filipecabaco filipecabaco deleted the fix/connect-backoff branch May 5, 2025 09:59
@kiwicopple
Copy link
Member

🎉 This PR is included in version 2.34.54 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

6 participants