可以在生产中使用 golang pprof 而不影响性能吗?

is it ok to use golang pprof on production without effecting performance?

我是 pprof 工具的新手,想知道是否可以在生产中保留 运行 这个工具。从我看过的文章来看,它似乎没问题而且是标准的,但是我对这如何不影响性能感到困惑,因为它每秒进行一次采样 N 次,为什么这不会导致性能下降。

Jaana Dogan does say in her article "Continuous Profiling of Go programs

Profiling in production

pprof is safe to use in production.
We target an additional 5% overhead for CPU and heap allocation profiling.

The collection is happening for 10 seconds for every minute from a single instance. If you have multiple replicas of a Kubernetes pod, we make sure we do amortized collection.
For example, if you have 10 replicas of a pod, the overhead will be 0.5%. This makes it possible for users to keep the profiling always on.

We currently support CPU, heap, mutex and thread profiles for Go programs.

Why?

Before explaining how you can use the profiler in production, it would be helpful to explain why you would ever want to profile in production. Some very common cases are:

  • Debug performance problems only visible in production.
  • Understand the CPU usage to reduce billing.
  • Understand where the contention cumulates and optimize.
  • Understand the impact of new releases, e.g. seeing the difference between canary and production.
  • Enrich your distributed traces by correlating them with profiling samples to understand the root cause of latency.

因此,如果您出于正确的原因使用 pprof,是的,您可以将其保留在生产环境中。
但是对于基本的监控,就像评论说的,系统就够了。

如“Continuous Profiling and Go" by Vladimir Varankin

Depending on the state of the infrastructure in the company, an “unexpected” HTTP server inside the application’s process can raise questions from your systems operations department ;)

At the same time, depending on the peculiar nature of a company, the very ability to access something inside a production application, that doesn’t directly relate to application’s business logic, can raise questions from the security department ;)) I

因此,在启用此类功能时,开销并不是唯一要考虑的标准。