-
Notifications
You must be signed in to change notification settings - Fork 6
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
Renew topic subscriptions only when they need to be #325
Comments
Topic subscriptions are technically ephemeral until persistence is implemented in the relay. See discussion. |
The legacy storage implementation requires at least two messages to extend TTL. |
Or a message in the 4xxx range, which is what we are doing here |
Oh yeah, the code was modified since I implemented it. My bad. |
Since we switched to IRN, we no longer need to publish a message to extend the subscription TTL to 30 days. Now the subscription TTL is 30 days by default. We may revert so let's not depend on this behavior for next couple weeks. This changes the math and potentially the strategy (we may not need to touch the database for now). Subscribing to all topics historically only took a couple of minutes when running in parallel. |
For now, renewing all topic subscriptions with cheap method: #388 In the future we can renew topic subscriptions only when the need to be. |
Currently we renew all topic subscriptions on startup and daily, but this is a lot of relay load all at once and is extremely inefficient. Renew them only when necessary instead.
Renewing a topic involves calling
subscribe
orbatch_subscribe
and subsequently publishing a 4050 message to the topic in order to extend the TTL to 30 days.The basic design involves keeping track of when a topic subscription was last renewed, or when it will expire, and storing this information in the database. The renewal job would scan the database for topics that need to be renewed, renew them, and then update the database entry.
This design does not require HS (horizontal scaling) (currently) or HA (high availability) because topic subscriptions are valid for 30 days, so we only need to renew them periodically, let's say every 28 days. If sequential renewals take 1s each, that allows us up to 2.5 million topics (
28*24*60*60
) able to be renewed continuously using a single instance. Further counts can be reached by parallelizing the renewals. 50x parallel (as we do currently) would allow up to 120 million topics to be maintained. If more than 120 million topics are required, then we should consider increasing the max TTL of subscriptions on the relay or implementing horizontal scaling here.With #362 we will have multiple replicas of Notify Server running. However, it's likely that without some type of lock all replicas will attempt to renew the same topics at the same time, resulting in redundant requests. Several options are available to mitigate this:
One more thing is that initially all the topics will be renewed at the same time, which would still result in spikes of renewals. It would be desirable to add an initial random spread to the renewal times over the course of 30 days, as well as adding randomness to the renewal date itself to keep the spread random over-time.
The text was updated successfully, but these errors were encountered: