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

Fixes #20998: Performance of compliance computation in ComplianceLevel can be improved #4237

Conversation

ncharles
Copy link
Member

@ncharles ncharles commented Apr 16, 2022

https://issues.rudder.io/issues/20998

This PR revisits the way ComplianceLevel are computed, to make it faster, and to fix issue in specific cases (ex, 200 succes, 199 repaired, 1 error, 1 missing, 1 unexpected , 1 non compliancere gives 47% success and 50% repaired with 0 precision)

All in all, the computation is ~4 times faster, mainly by using Long computation rather than BigDecimal
The drawback is that we can't go further than precision 5 (I can't seem to see which use case would need more than that), so computation are made using Long, by multiplying with the power of ten, and then truncating.

It also introduces a method to compute compliance directly without pending result, so that we can skip the duplication of ComplianceLevel and the creation of a CompliantPercent

It is not enough to make the display of the Nodes list instantaneous in the Rule detail page, but my tests show it's twice as fast as before. Unfortunately the way it's done computed twice by level the compliance (once without pending, and one with pending), and it's made for the Rule, and then each Directives and Nodes, and then for each components, etc etc.
The API answers on my test platform in 2.4s (from 4.5s before) - removing all compliance computation makes it answer in 1s (which is the cost of getting the Groups and Rules)

@ncharles ncharles requested a review from fanf April 16, 2022 05:05
@ncharles ncharles added Trigger test WIP Use that label for a Work In Progress PR that must not be merged yet and removed Trigger test labels Apr 16, 2022
@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles
Copy link
Member Author

i'm unsure this does anything meaningfull at this point, I have only one working test and no valid support of precision

@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles ncharles added Trigger test and removed Trigger test WIP Use that label for a Work In Progress PR that must not be merged yet labels Apr 22, 2022
@ncharles
Copy link
Member Author

ncharles commented May 5, 2022

PR updated with a new commit

@ncharles
Copy link
Member Author

ncharles commented May 5, 2022

PR updated with a new commit

@fanf
Copy link
Member

fanf commented May 11, 2022

what s the status of that PR ? There is some commented out tests, should I still review it now ?

@ncharles
Copy link
Member Author

You can review it. The tests are commented because they fail, but they failed also before (well, they didn't exist)

def pc_for(i:Int) : Double = {
if(i == 0) {
// these depends on the precision
val diviser = divisers(precision)
Copy link
Member Author

Choose a reason for hiding this comment

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

@fanf do you know what's the cost of doing an assert ? I'll need to assert that prevision is <=5

Copy link
Member

Choose a reason for hiding this comment

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

create a case class precision with case object Level1 to Level5 and its value setted. It should not be perf impacting (object are global, and accessing a static field is very quick, and the traduction to level is only done at border like API so not important)

@ncharles
Copy link
Member Author

PR updated with a new commit

@Normation-Quality-Assistant
Copy link
Contributor

This PR is not mergeable to upper versions.
Since it is "Ready for merge" you must merge it by yourself using the following command:
rudder-dev merge https://github.com/Normation/rudder/pull/4237
-- Your faithful QA
Kant merge: "Thoughts without content are empty, intuitions without concepts are blind."
(https://ci.normation.com/jenkins/job/merge-accepted-pr/54192/console)

@ncharles
Copy link
Member Author

OK, squash merging this PR

@ncharles ncharles force-pushed the bug_20998/performance_of_compliance_computation_in_compliancelevel_can_be_improved branch from b68962b to 970667c Compare May 13, 2022 07:21
@ncharles ncharles merged commit 970667c into Normation:branches/rudder/7.0 May 13, 2022
@ncharles
Copy link
Member Author

OK, merging this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants