Video in progress

Is it worth adding continuous profiling as a fourth signal next to metrics, logs and traces? When does it pay off?

In most cases yes: a profile answers "why is CPU or memory usage so high" down to the line of code, which the other signals can't do. Sampling profilers like async-profiler and JFR are cheap enough to leave on all the time in prod. The most value comes from optimizing CPU cost and catching regressions between deploys.

📖 Answer

A metric says "CPU 80%", a trace says "this span is 400 ms", but none of them says "30% of the time goes into creating ObjectMappers". To find that you used to have to attach a profiler by hand during the problem, and the problem often didn't reproduce at that moment.

Continuous profiling (Pyroscope, Parca, Datadog Profiler and others) takes small samples from every pod all the time and stores them. In Java the base is usually async-profiler or JFR.

Cases where it pays off:

  • Cost: in a large fleet (hundreds of pods), saving a few percent of CPU is real money on the infrastructure bill. The biggest "columns" in the flame graph are often in unexpected places: log formatting, regex compilation, repeated serialization.
  • Comparing versions: "diff the profiles of v1.42 and v1.43" shows directly which method the regression appeared in.
  • Rare problems: CPU spikes for 2 minutes once a day. Because there is a continuous profile, you can open those 2 minutes later.
  • Allocation and lock profiles: they show the source of GC pressure and which lock is being waited on.

Trade-offs and risks:

  • overhead is usually below a few percent but depends on the setup; wall-clock and allocation profiling cost more than CPU profiling, so measure on a canary and then roll out;
  • storage volume: profiles are compact, but hundreds of pods × a 10-second interval add up to a lot;
  • the container may need perf_events permissions, which you have to agree on with the security team;
  • linking to traces (adding a profile ID to a span) is not equally mature in every tool.

I usually start with one or two services that have big costs, show the savings found in the first month, and then propose adding it to the platform defaults.