Support enabling redis presence user mapping for much faster presence stats retrieval #754
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
Relates #750
Currently to get presence stats in Redis engine case, Centrifugo loads entire presence to memory and then calculates
num_clients
andnum_users
counters. This may be inefficient for channels with huge number of active subscribers.This pr Introduces boolean option
global_redis_presence_user_mapping
. Whentrue
: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).