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

Counter API is overly restrictive #108

Open
unrealhoang opened this issue Nov 11, 2022 · 1 comment
Open

Counter API is overly restrictive #108

unrealhoang opened this issue Nov 11, 2022 · 1 comment

Comments

@unrealhoang
Copy link

unrealhoang commented Nov 11, 2022

Currently Counter's API is:
https://github.com/prometheus/client_rust/blob/master/src/metrics/counter.rs#L76-L83

    /// Increase the [`Counter`] by 1, returning the previous value.
    pub fn inc(&self) -> N {
        self.value.inc()
    }

    /// Increase the [`Counter`] by `v`, returning the previous value.
    pub fn inc_by(&self, v: N) -> N {
        self.value.inc_by(v)
    }

which requires inc and inc_by to return the previous value. This is rarely needed for metric collecting use-case, and it hinders the ability to use per-thread thread-local accumulator to prevent contention (like this) and increase performance.

@rapiz1
Copy link

rapiz1 commented Nov 29, 2022

I believe a thread local counter will benefit the performance. Considering a counter on each HTTP request, a shared lock is the last thing I want on my critical path.

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

2 participants