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

Metric benchmark investigation #5544

Closed
wants to merge 11 commits into from
Closed

Conversation

dashpole
Copy link
Contributor

@dashpole dashpole commented Jun 25, 2024

Looking into #5542. Closing, as this is not meant to be merged.

My original local benchmark:

$ go test -benchmem -benchtime=2s -bench=Bench .
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/opentelemetry-go/sdk/benchmark
cpu: AMD EPYC 7B12
BenchmarkPrometheusCounter-24       	762422826	         3.154 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounter-24             	21401206	       113.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	 8772984	       271.5 ns/op	      16 B/op	       1 allocs/op

Exemplar collection accounts for ~50ns of the overhead (a1bead9), even though I believe we shouldn't be collecting exemplars by default, and we aren't doing tracing. This is probably a good area to optimize.

BenchmarkOTELCounter-24             	42491396	        56.06 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	10961318	       220.1 ns/op	      16 B/op	       1 allocs/op

Attribute cardinality limiting seems to account for a very small (~2ns) portion of the overhead.

Lookup based on the attribute set accounts for ~40ns of the overhead for the no-attributes case, and the vast majority of the overhead for the with-attributes case. OTel would need to introduce bound instruments to remove this chunk of overhead.

BenchmarkOTELCounter-24             	148504042	        16.23 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	38502283	        61.73 ns/op	      16 B/op	       1 allocs/op

Our counter increment function (with locking) accounts for ~8ns of the overhead. We use a simple lock and increment a counter value. Prometheus appears to have implemented some optimizations for this. Benchmarks without any measurement whatsoever:

BenchmarkOTELCounter-24             	299598176	         7.974 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	43538810	        55.06 ns/op	      16 B/op	       1 allocs/op

The remaining overhead is from the API, and from the Options pattern which requires calling NewAddConfig. This would presumably be eliminated if instruments were already bound to attributes.

BenchmarkOTELCounter-24             	42491396	        56.06 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	10961318	       220.1 ns/op	      16 B/op	       1 allocs/op
BenchmarkOTELCounter-24             	42471098	        55.09 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	11157889	       214.9 ns/op	      16 B/op	       1 allocs/op
BenchmarkOTELCounter-24             	148504042	        16.23 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	38502283	        61.73 ns/op	      16 B/op	       1 allocs/op
BenchmarkOTELCounter-24             	299598176	         7.974 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	43538810	        55.06 ns/op	      16 B/op	       1 allocs/op
BenchmarkOTELCounter-24             	377620942	         6.333 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	47813799	        52.70 ns/op	      16 B/op	       1 allocs/op
BenchmarkOTELCounter-24             	469475085	         5.119 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24    	46523139	        51.32 ns/op	      16 B/op	       1 allocs/op
BenchmarkOTELCounter-24                 	464676590	         5.082 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24        	48377798	        51.73 ns/op	      16 B/op	       1 allocs/op
BenchmarkNoOpOTELCounter-24             	1000000000	         1.901 ns/op	       0 B/op	       0 allocs/op
BenchmarkNoOpOTELCounterWithLabel-24    	64543243	        34.60 ns/op	      16 B/op	       1 allocs/op
BenchmarkOTELCounter-24                 	685085875	         3.493 ns/op	       0 B/op	       0 allocs/op
BenchmarkOTELCounterWithLabel-24        	66929808	        36.21 ns/op	      16 B/op	       1 allocs/op
BenchmarkNoOpOTELCounter-24             	1000000000	         1.901 ns/op	       0 B/op	       0 allocs/op
BenchmarkNoOpOTELCounterWithLabel-24    	66596236	        35.09 ns/op	      16 B/op	       1 allocs/op
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.

1 participant