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

Support enabling redis presence user mapping for much faster presence stats retrieval #754

Merged
merged 1 commit into from
Jan 13, 2024

Conversation

FZambia
Copy link
Member

@FZambia FZambia commented Jan 2, 2024

Proposed changes

Relates #750

Currently to get presence stats in Redis engine case, Centrifugo loads entire presence to memory and then calculates num_clients and num_users counters. This may be inefficient for channels with huge number of active subscribers.

This pr Introduces boolean option global_redis_presence_user_mapping. When true:

Centrifugo will maintain additional per-user data structures in Redis when updating presence information (for all channels with presence enabled). Similar to structures used for general client presence (i.e. additional ZSET + HASH). So we get a possibility to efficiently get the number of unique users. This allows improve performance of presence stats API command significantly since we replace calculation of presence stats counters from Centrifugo based on full presence info to Redis based on efficient queries to data structures.

For the channel with 100k unique subscribers number of presence stats ops bumped from 15 to 200000 per second in my benchmark.

This will increase memory usage in Redis, possibly up to 2x from what was spent on presence information before (less if you have extra info in client information attached, since we do not include info payload to user structures).

@FZambia FZambia changed the title Support enabling redis presence user mapping Support enabling redis presence user mapping for much faster presence stats retrieval Jan 2, 2024
@FZambia FZambia merged commit d4db556 into master Jan 13, 2024
4 checks passed
@FZambia FZambia deleted the support_redis_presence_user_mapping branch January 13, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant