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

Make Counter faster for simple Inc or Add with an integer #367

Merged
merged 4 commits into from
Jan 19, 2018

Conversation

beorn7
Copy link
Member

@beorn7 beorn7 commented Jan 19, 2018

@grobie
@smcquay This is implementing what I had suggested on top of your change.

smcquay and others added 4 commits December 15, 2017 11:03
Specifically @beorn7 pointed out that the previous implementation had
some shortcomings around large numbers. I've changed the code to match
the suggestion in review, as well as added a few test cases.
Original discussion see
#362 .

Assuming that the most frequently used method of a `Gauge` is `Set`
and the most frequently used method of a `Conuter` is `Inc`, this
separates the implementation of both metric types. `Inc` and integral
`Add` of a counter is now handled in a separate `uint64`. This would
create a race in `Set`, but luckily, there is no `Set` anymore in a
counter.

All attempts to solve above race (to use the same idea for a `Gauge`)
slow down `Set`, So we just stick with the old implementation
(formerly `value`) for `Gauge`.
@beorn7 beorn7 mentioned this pull request Jan 19, 2018
Copy link
Member

@grobie grobie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Adding a benchmark to this repo would be great.

@beorn7
Copy link
Member Author

beorn7 commented Jan 19, 2018

The existing BenchmarkCounterNoLabels covers this:

BEFORE:

BenchmarkCounterNoLabels-4   100000000               16.4 ns/op             0 B/op          0 allocs/op

AFTER:

BenchmarkCounterNoLabels-4   200000000                8.10 ns/op            0 B/op          0 allocs/op

@beorn7
Copy link
Member Author

beorn7 commented Jan 19, 2018

@smcquay had more sophisticated benchmarks, I believe. If they could be contributed easily, I would appreciate it.

@beorn7 beorn7 merged commit b49b54c into master Jan 19, 2018
@beorn7 beorn7 deleted the beorn7/counter branch January 19, 2018 18:47
@smcquay
Copy link
Contributor

smcquay commented Jan 19, 2018

I will dig them up and submit them.

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

Successfully merging this pull request may close these issues.

None yet

3 participants