Skip to content

off-cpu: Use a probability value for the threshold#460

Merged
christos68k merged 8 commits intoopen-telemetry:mainfrom
rockdaboot:off-cpu-probability
Jul 11, 2025
Merged

off-cpu: Use a probability value for the threshold#460
christos68k merged 8 commits intoopen-telemetry:mainfrom
rockdaboot:off-cpu-probability

Conversation

@rockdaboot
Copy link
Copy Markdown
Contributor

PoC for using a probability value for the off-cpu threshold.

Use a probability value of [0..1] for the -off-cpu-threshold as suggested in #458.

Fixes #459

@rockdaboot rockdaboot self-assigned this May 12, 2025
@rockdaboot rockdaboot requested review from a team as code owners May 12, 2025 14:55
@rockdaboot
Copy link
Copy Markdown
Contributor Author

@open-telemetry/ebpf-profiler-approvers Can I get feedback please?

Comment thread tracer/tracer.go
// configured off-cpu threshold.
// To not lose too many scheduling events but also not oversize sched_times,
// calculate a size based on an assumed upper bound of scheduler events per
// second (1000hz) multiplied by an average time a task remains off CPU (3s),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[..] an average time a task remains off CPU (3s) - is there some evidence for this number? From local workload I see significant different (lower) values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't change the text, just moved it. Maybe @christos68k can give some background how exactly he measured this number.

Copy link
Copy Markdown
Contributor Author

@rockdaboot rockdaboot May 27, 2025

Choose a reason for hiding this comment

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

Otherwise, what is your preferred number here @florianl?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I went for relaxed rather than tight sizing here.

Comment thread tracer/tracer.go
// Guarantee a minimal size of 16.
return 16
}
if size > 4096 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With a given probability value of 1.0 I would expect every scheduling event to show up. With this change, this is not possible, as the size of sched_times becomes the limiting factor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The behavior for 1.0 is the same as for 1000 before.
Before: adaption["sched_times"] = (4096 * cfg.OffCPUThreshold) / support.OffCPUThresholdMax results in 4096 for all (=1000).
This PR: User enters 1.0, which is threshold = math.MaxUint32, so the result is also 4096.

Copy link
Copy Markdown
Member

@florianl florianl left a comment

Choose a reason for hiding this comment

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

Use a probability value of [0..1] for the -off-cpu-threshold as suggested in #458.

This might not be correct, as #458 was closed with this comment:

Ok, that's my fault, I was testing a patch to increase OffCPUThresholdMax to 1 billion, and that was causing the problem. Thanks for help, closing the issue.

@rockdaboot
Copy link
Copy Markdown
Contributor Author

Use a probability value of [0..1] for the -off-cpu-threshold as suggested in #458.

This might not be correct, as #458 was closed with this comment:

Ok, that's my fault, I was testing a patch to increase OffCPUThresholdMax to 1 billion, and that was causing the problem. Thanks for help, closing the issue.

The issue description included "and BTW it would be better to have more granularity than per-mille for off cpu profiling which is giving me thousands of samples per sec". This was the reason why the OP (desperately!?) tried to patch the code. With this PR, nobody has to patch the code, but can go lower than 1 out of thousand samples.

@rockdaboot rockdaboot force-pushed the off-cpu-probability branch from e8d7ece to edaf5d9 Compare May 27, 2025 17:03
Comment thread testutils/helpers.go Outdated
Co-authored-by: Florian Lehner <florian.lehner@elastic.co>
@christos68k christos68k merged commit 79d08a7 into open-telemetry:main Jul 11, 2025
27 checks passed
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Aug 12, 2025
Co-authored-by: Florian Lehner <florian.lehner@elastic.co>
gnurizen pushed a commit to parca-dev/opentelemetry-ebpf-profiler that referenced this pull request Aug 13, 2025
Co-authored-by: Florian Lehner <florian.lehner@elastic.co>
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.

Off-cpu profiling threshold: Use probability instead of per-mille value

3 participants