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

Add simple sharding in ValueMap to boost metrics update performance under stress. #2297

Open
fraillt opened this issue Nov 11, 2024 · 0 comments

Comments

@fraillt
Copy link
Contributor

fraillt commented Nov 11, 2024

Idea is not new, it was tried in #1564, but implementation will be new :)

At the moment we have trackers: RwLock<HashMap<Vec<KeyValue>, Arc<A>>>, changing it to trackers: Vec<RwLock<HashMap<Vec<KeyValue>, Arc<A>>>>, is not enough, because attribute-sets supposed to be order agnostic, so we need to make sure that same attribute-set (even if key order is different) would use same tracker.
The idea is to have this structure instead:

            all_attribs: Vec<RwLock::new(HashMap::new())>,
            sorted_attribs: Mutex::new(HashMap::new()),

all_attribs will be sharded by attribute-set as it is, so updating it will be very fast, but for every new value we'll always need to insert into sorted_attribs. (All of this, except sharding part is implemented in #2288, and performance is mostly not affected, in addition it solves another issue as well #2093)

To implement actual sharding we need to a way to calculate shard index from attribute-set hash, so we need stable and preferably fast hashing function. #2296 deals with this issue.
Once both of these task are done, implement sharding becomes very straight forward.

I have tested this locally (by merging both tasks and implementing sharding on top), and results on 12 core CPU, with 24 shards, was ~5x improvement for stress test (metrics_histogram)
Throughput: 4,570,800 iterations/sec
vs
Throughput: 23,165,800 iterations/sec

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

No branches or pull requests

1 participant