Skip to content

Expose shard index used for metrics purposes #335

@tfreiberg-fastly

Description

@tfreiberg-fastly

We want to instrument our use of a large, single dashmap in our server process with some metrics like lock held time.
These metrics are only accurate if we can track which shard we operate on.
For now we're simply recording metrics for the entire dashmap and the shard count, which gives us the average per shard but nothing more.

The current raw-api feature theoretically allows getting the shard, but it requires us to hash twice, once to get the shard and once inside dashmap, which is an unacceptable waste of work.

I can think of two possible solutions, both of which would require an API change (or a private fork):

  1. Make many more internals public with the raw-api feature (similar to what Consider making RefMut::new public when raw-api is enabled #248 asks for) and reimplement get/get_mut/entry_ref in our codebase, giving us visibility of the shard index for free.
  2. Adding variants of the main public methods that also return the shard index, e.g. get_mut_with_shard_index(..) -> (Option<RefMut<...>>, usize or something like that, probably behind a new feature flag

I would be willing to implement any of these, if they're welcome, but i'm aware that they're both not very elegant ideas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions