Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimisations and cleanups #173

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

NelsonVides
Copy link
Member

@NelsonVides NelsonVides commented Mar 3, 2025

This PR proposes a miscellaneous of updates and improvements to the repo. Commits are well organised by topics and with good descriptions, so that'd be the best way to review the whole thing, as some changes are not related to each other – but are some times too small to be moved to their own PR, which I could easily do if any of you would prefer me to do anyways.


EDIT: #173 (comment)

@NelsonVides NelsonVides force-pushed the optimisations_and_cleanups branch from b29b665 to 4041d2b Compare March 3, 2025 12:00
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/metrics/prometheus_counter.erl 94.31% <ø> (ø)
src/metrics/prometheus_histogram.erl 95.74% <ø> (ø)
src/model/prometheus_model_helpers.erl 94.25% <100.00%> (-0.07%) ⬇️
src/prometheus_buckets.erl 97.29% <100.00%> (-0.08%) ⬇️
src/prometheus_sup.erl 77.41% <100.00%> (-0.71%) ⬇️
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NelsonVides NelsonVides force-pushed the optimisations_and_cleanups branch 2 times, most recently from 90a3ec7 to 32492a9 Compare March 3, 2025 12:10
@NelsonVides NelsonVides marked this pull request as ready for review March 3, 2025 12:16
Copy link
Member

@onno-vos-dev onno-vos-dev left a comment

Choose a reason for hiding this comment

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

Haven't had the time to look through all commits yet but sharing these two review comments as a start

@@ -90,7 +90,7 @@ inc(Caller) ->
-define(TABLE, ?PROMETHEUS_COUNTER_TABLE).
-define(ISUM_POS, 2).
-define(FSUM_POS, 3).
-define(WIDTH, 16).
-define(WIDTH, erlang:system_info(schedulers_online)).
Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead of fixing this to be schedulers_online we can set this up as an application:get_env(<application>, <some_name>, 16) so the original remains preserved but we open up the loophole for setting a higher value.

Copy link

Choose a reason for hiding this comment

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

Another issue is that schedulers_online can change value dynamically at runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. Should use just schedulers, as that can't change at runtime.

On the other hand I'm not sure it'd help to make it configurable, currently the algorithm that chooses the key would do X band (?WIDTH - 1), so most values would mean skewing the distribution of schedulers to each key and some keys would see more contention than others. Sensibly, if we're keying on the scheduler id, the only values that make sense are multiples (or halves) of the number of schedulers.

@@ -95,7 +95,7 @@ the number of time ticks when the recent value was observed).
-define(ISUM_POS, 3).
-define(FSUM_POS, 4).
-define(BUCKETS_START, 5).
-define(WIDTH, 16).
-define(WIDTH, erlang:system_info(schedulers_online)).
Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead of fixing this to be schedulers_online we can set this up as an application:get_env(<application>, <some_name>, 16) so the original remains preserved but we open up the loophole for setting a higher value.

@NelsonVides
Copy link
Member Author

I guess this PR is too big to review, so I've split it into #175 for the uncontroversial, #176 for the most convoluted, and left here maybe the most interesting changes.

Note that the histogram table actually requires read concurrency,
as on every insert first parameters need to be looked up.

Otherwise this makes it more flexible to configure any table
independently and precisely, may the need arise.
Note that the current configuration would distribute the load badly: the
key is chosen by bitwise-and on the scheduler ID, but if we have more
schedulers than 16, then some keys would see twice as much contention
than others, see for example, if we had 24:

```
1> [ X band 15 || X <- lists:seq(1, 24)].
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8]
```
Examine the condition inlined in the helper instead of passing a
function object. Also ensure that the entry point has checked the types,
when looping on the inner function, the JIT compiler will know already
that the inputs are lists and numbers, skipping dynamic type checking on
every iteration. The `lists` module implements such optimisation
extensively.
@NelsonVides NelsonVides force-pushed the optimisations_and_cleanups branch from eb19b61 to e2c2b50 Compare March 9, 2025 09:33
@NelsonVides NelsonVides requested a review from onno-vos-dev March 9, 2025 09:35
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.

3 participants