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

Switch MinMaxSumCount to a mutex lock instead of StateLocker #667

Merged
merged 4 commits into from
Apr 29, 2020

Conversation

evantorrie
Copy link
Contributor

@evantorrie evantorrie commented Apr 27, 2020

Fixes #625
Unblocks #657

As noted in #600, with multiple values being modified for each Update(), a single mutex lock and non-atomic operations ends up being faster than making each value update into an atomic operation.

With multiple values being modified for each Update(), a single mutex
lock and non-atomic operations ends up being faster than making each
value update into an atomic operation.
@evantorrie
Copy link
Contributor Author

I've left the old StateLocker approach so that I can include the benchmarks. We should remove this before merging.

@@ -66,8 +68,8 @@ var (
func TestMain(m *testing.M) {
fields := []ottest.FieldOffset{
{
Name: "Aggregator.states",
Offset: unsafe.Offsetof(Aggregator{}.states),
Name: "Aggregator.current",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is no longer using atomics, we don't strictly need to check any offsets for alignment. Shall I just remove?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of this change, you could just change Aggregator to AggregatorSL.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, wait. AggregatorSL will be dropped anyway. Then this whole TestMain function could be dropped.

@jmacd jmacd added the area:metrics Part of OpenTelemetry Metrics label Apr 28, 2020
@@ -66,8 +68,8 @@ var (
func TestMain(m *testing.M) {
fields := []ottest.FieldOffset{
{
Name: "Aggregator.states",
Offset: unsafe.Offsetof(Aggregator{}.states),
Name: "Aggregator.current",
Copy link
Member

Choose a reason for hiding this comment

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

Instead of this change, you could just change Aggregator to AggregatorSL.

@@ -66,8 +68,8 @@ var (
func TestMain(m *testing.M) {
fields := []ottest.FieldOffset{
{
Name: "Aggregator.states",
Offset: unsafe.Offsetof(Aggregator{}.states),
Name: "Aggregator.current",
Copy link
Member

Choose a reason for hiding this comment

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

Ah, wait. AggregatorSL will be dropped anyway. Then this whole TestMain function could be dropped.

@evantorrie
Copy link
Contributor Author

On my somewhat underpowered machine, here are what I get for comparison between the mutex and stateLocker approach using the benchmarks in mmsc_test.go

BenchmarkMinMaxSumCountAggregators
BenchmarkMinMaxSumCountAggregators/mutex
BenchmarkMinMaxSumCountAggregators/mutex-8        	36357776	        38.3 ns/op
BenchmarkMinMaxSumCountAggregators/statelocker
BenchmarkMinMaxSumCountAggregators/statelocker-8  	22305990	        54.6 ns/op
BenchmarkMinMaxSumCountAggregatorsRunParallel
BenchmarkMinMaxSumCountAggregatorsRunParallel/mutex
BenchmarkMinMaxSumCountAggregatorsRunParallel/mutex-8         	16282167	        86.8 ns/op
BenchmarkMinMaxSumCountAggregatorsRunParallel/statelocker
BenchmarkMinMaxSumCountAggregatorsRunParallel/statelocker-8   	11320578	       107 ns/op

@jmacd
Copy link
Contributor

jmacd commented Apr 28, 2020

This is ready to merge. Do you want to remove the SL version before merging? I don't mind doing that in a future PR (which could also remove the StateLocker).

@evantorrie
Copy link
Contributor Author

This is ready to merge. Do you want to remove the SL version before merging? I don't mind doing that in a future PR (which could also remove the StateLocker).

Removed StateLocker and the referencing Benchmarks

@evantorrie
Copy link
Contributor Author

I believe only this remaining question needs to be answered before merging.

@jmacd jmacd merged commit bd16ce0 into open-telemetry:master Apr 29, 2020
evantorrie added a commit to evantorrie/opentelemetry-go that referenced this pull request Apr 30, 2020
Fixes open-telemetry#657

With the changes in open-telemetry#667 and open-telemetry#669 to use a plain-old-mutex for
concurrent access of Histogram and MinMaxSumCount aggregators,
the StateLocker implementation is no longer used in the project.
jmacd added a commit that referenced this pull request Apr 30, 2020
Fixes #657

With the changes in #667 and #669 to use a plain-old-mutex for
concurrent access of Histogram and MinMaxSumCount aggregators,
the StateLocker implementation is no longer used in the project.

Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
@MrAlias MrAlias added this to the Implement v0.4.0 Specification milestone Jun 3, 2020
@evantorrie evantorrie deleted the mutex-mmsc2 branch June 23, 2020 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reimplement MinMaxSumCount aggregator using mutex rather than lock-free atomic algorithm
4 participants