Skip to content

Conversation

@AlliBalliBaba
Copy link
Contributor

After looking at the current main branch ,I noticed that metrics got a lot slower, mainly due to With() creating a new Prometheus label each time.

This PR changes WIth() to WithLabelValues() which makes metrics collection twice as fast (from ~6% of optimized request time to ~3%)

It would probably also be nice if there was a way to disable metrics collection entirely since they often end up not being used. Or maybe pull these metrics in the hot path instead of pushing them on each request.

.With()
image

.WithLabelValues()
image

@AlliBalliBaba
Copy link
Contributor Author

fyi @IndraGunawan

@IndraGunawan
Copy link
Contributor

IndraGunawan commented Mar 24, 2025

@AlliBalliBaba i have one question, i can generate the flamegraph by following this https://github.com/dunglas/frankenphp/blob/main/testdata/performance/performance-testing.md

what command/tools to compare 2 profiles, so I know the performance diff, like this (from ~6% of optimized request time to ~3%) ?

@dunglas dunglas merged commit f36bd51 into main Mar 24, 2025
58 checks passed
@dunglas dunglas deleted the perf/metrics-collection branch March 24, 2025 09:14
@AlliBalliBaba
Copy link
Contributor Author

@IndraGunawan you can ctrl+f inside of the flamegraphs (when opening them in a browser) and then search for 'Prometheus'. It will show on the bottom right how much of the CPU profile matches.

The amount of % depends though on which endpoints you are spamming and how hard you are spamming them.

Generally it's best to take performance metrics always with a grain of salt, especially in these 'Hello World' situations. What the flamegraph shows in this case is just that WithLabelvalues is roughly twice as efficient as With.

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.

4 participants