TopK proposal
#3259
Replies: 1 comment 2 replies
-
|
Hi, thank you for your proposal. Several questions after a glance:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
In #3176, we plan to support the TopK algorithm in Redis.
RedisTopK is a redis module that can be used find top-k elephant flows. It is based on the TopK, which is a probabilistic data structure that can be used to find the top k elements by frequency of occurrence in a set.
Core Concepts
Data Structure Design
Metadata
Bucket
HeapBucket
TopK
size_t heap_size; std::vector<std::vector<Bucket>> buckets; std::vector<HeapBucket> heap;Operations
TOPK.RESERVE
Init the topk structure.
Parameters:
key: The key name of the Top-K structure.
k: The number of highest-frequency elements to track.
width(optional): The number of counters in each bucket, with default value of 7.
depth(optional): The number of buckets in each level, with default value of 8.
decay(optional): The decay probability when counters collide, with default value of 0.9.
example:
Implementation:
TOPK.ADD
Add an element to the Top-K structure.
Parameters:
key: The key name of the Top-K structure.
item: The element to be added.
example:
Implementation:
Case 1: the bucket count is 0, set fingerprint of the item and count to 1.
Case 2: if the bucket fingerprint equals to the item fingerprint, and the item is in HeapBucket, the count of the bucket increase 1.
Case 3: decay the count of the bucket. if count is 0, set fingerprint of the item and count to 1.
TOPK.QUERY
Return is element in the Top-K structure.
Parameters:
key: The key name of the Top-K structure.
item: The element to be queried.
example:
Implementation:
TOPK.LIST
Return the list of elements in the Top-K structure.
Parameters:
key: The key name of the Top-K structure.
example:
Implementation:
TOPK.INFO
Return the information of the Top-K structure.
Parameters:
key: The key name of the Top-K structure.
example:
Implementation:
TOPK.INCRBY
Increment the count of an element in the Top-K structure.
Parameters:
key: The key name of the Top-K structure.
item: The element to be incremented.
count: The amount to increment the count by.
example:
Implementation:
similar to TOPK.ADD, but instead of adding one count of element to the topk structure, it increments the count of the element by your parameter.
Reference
https://redis.io/docs/latest/develop/data-types/probabilistic/top-k/
https://redis.io/docs/latest/commands/?group=topk
https://www.usenix.org/conference/atc18/presentation/gong
Beta Was this translation helpful? Give feedback.
All reactions