Closed joshuatroy closed 2 years ago
Could you show the code you use the otlphttp instrumentation library? I tried to use the example code in
to start a simple server and client, and mock 10000 requests sent to server, the memory usage is not changing so fast like your case.
And the most usage of memory is not global.(*siInstProvider).Counter
and global.(*siInstProvider).Histogram
Hey @fatsheep9146 sorry for my delay in responding.
The problem was in fact how we were using the library. A new otelhttp handler was being created on every request inside some middleware, instead of being created once and re-used!
Hi OpenTelemetry team 👋
We are using the go.opentelemetry.io/otel and go.opentelemetry.io/contrib packages at my work. They are part of our core library which manages the lifecycle of services (e.g. simplifies how we register HTTP/gRPC endpoints / how we setup RabbitMQ/Kafka consumers/how we deal with Liveness/Readiness probes / how we register and collect metrics etc).
This library is used by majority of our go micro services. In May, we upgraded our opentelemetry packges in the core library:
We then released a new tagged version of our core library. As services started using the new version of our core library, we started to notice some memory leaks. The metrics driving the graphs below come from kubernetes, and specifically a services container. And we're seeing a similar leak across all services that have upgraded to our new core library (that uses the go.opentelemetry.io/otel and go.opentelemetry.io/contrib library).
So we used pprof to take a look at the services heap and generated a SVG below:
We can see that
go.opentelemetry.io/otel/metric/internal/global.(*siInstProvider).Counter
has the largest flat and cumulative memory.We can also confirm this using pprof cli (and I've just replaced company git and service with some example names).
So the createMeasures function call lead me here, but as I'm creating this issue I'm wondering whether it should be raised against this repository or the go.opentelemetry.io/otel/metric one.
We have also tried upgrading to a later versions of these libraries but the issue is still there.
What version of Go and opentelemetry-go-contrib are you using? Go 1.17 opentelemetry-go-contrib v1.7.0
What operating system and processor architecture are you using? OS: Linux Architecture: x86_64
What did you do? Upgraded go.opentelemetry.io libraries
What did you expect to see? No memory changes
What did you see instead? Memory leak