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 #20758: Improve node computation #4172

Conversation

ncharles
Copy link
Member

@ncharles ncharles commented Feb 13, 2022

Based on #4164

Changing the types to remove most of the hashCode computation, most notably, using Set for NodeInfo is a really bad idea
With this (unfinished) code, computation of dynamic group goes from 1m15 (pr 4164) to 35s
Do not merge for now, this is only exploration

The only relevant thing is to return nodeId rather than NodeInfos now that we don't need serverrole info

@ncharles ncharles added the WIP Use that label for a Work In Progress PR that must not be merged yet label Feb 13, 2022
@ncharles
Copy link
Member Author

Do not review, still a wip

query.returnType match {
case NodeReturnType =>
// we have a special case for the root node that always never to that group, even if some weird
// scenario lead to the removal (or non addition) of them
val withoutServerRole = inNodes.filterNot { case QueryResult(e, inv, _) => e(A_NODE_UUID) == Some("root") }
val withoutServerRole = foundNodes.filterNot { case x: NodeId => x.value == "root" }
Copy link
Member Author

Choose a reason for hiding this comment

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

It should no't be root, it will miss all relays!

case NodeReturnType =>
// we have a special case for the root node that always never to that group, even if some weird
// scenario lead to the removal (or non addition) of them
foundNodes.filterNot { case x: NodeId => x.value == ("root") }
Copy link
Member Author

Choose a reason for hiding this comment

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

same here, it cannot be only root

@ncharles ncharles force-pushed the bug_20758/improve_node_computation branch from e8c0358 to ef432ce Compare July 20, 2022 14:47
@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles ncharles removed the WIP Use that label for a Work In Progress PR that must not be merged yet label Jul 20, 2022
@@ -875,6 +876,10 @@ trait NodeInfoServiceCached extends NodeInfoService with NamedZioLogger with Cac
def getNodeInfos(nodeIds: Set[NodeId]): IOResult[Set[NodeInfo]] = withUpToDateCache(s"${nodeIds.size} nodes infos") { cache =>
cache.filter(x => nodeIds.contains(x._1)).values.map( _._2).toSet.succeed
}

def getNodeInfosSeq(nodeIds: Seq[NodeId]): IOResult[Seq[NodeInfo]] = withUpToDateCache(s"${nodeIds.size} nodes infos") { cache =>
nodeIds.map(id => cache(id)).map(_._2).succeed
Copy link
Member

Choose a reason for hiding this comment

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

it could fail if some requested node id are not in cache (for some inconsistency from somewhere).
What is the correct thing to do on missing nodeId ? Fail everything or ignore ?
If fail, something like:

ZIO.foreach(nodeIds) { id => cache.get(id).map(_._2).notOptionnal(s"node with id ${id.value} not in cache, likely an error")} }

If ignore:

nodeIds.map(id => cache.get(id).map(_._2)).collect { case Some(info) => info }.succeed
}```

Copy link
Member Author

Choose a reason for hiding this comment

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

ha, very good point.
to be consistent, we should ignore, so the second approach is the right one. Thank you !

} else {
foundNodeInfos.filter { nodeinfo => predicate(nodeinfo, predicates, composition, None) }
foundNodeInfos.flatMap { case nodeinfo => if (predicate(nodeinfo, predicates, composition, None)) { Some(nodeinfo.id) } else None }
Copy link
Member

Choose a reason for hiding this comment

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

can be directly

foundNodeInfos.collect { case nodeinfo if (predicate(nodeinfo, predicates, composition, None)) => nodeinfo.id } 

Copy link
Member Author

Choose a reason for hiding this comment

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

actually, it could still be the filter

Copy link
Member Author

Choose a reason for hiding this comment

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

the collect is better, it avoids one creation of collection

Copy link
Member

@fanf fanf left a comment

Choose a reason for hiding this comment

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

Appart from the very small feedback, that seems great!
You can self merge once your change are commited

@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/4172
-- Your faithful QA
Kant merge: "Live your life as though your every act were to become a universal law."
(https://ci.normation.com/jenkins/job/merge-accepted-pr/57705/console)

@fanf
Copy link
Member

fanf commented Aug 1, 2022

OK, squash merging this PR

@fanf fanf changed the title Fixes #20716: Improve dynamic group computation speed Fixes #20758: Improve node computation Aug 1, 2022
@fanf fanf force-pushed the bug_20758/improve_node_computation branch from 68904dd to adc1b18 Compare August 1, 2022 12:05
@fanf fanf merged commit adc1b18 into Normation:branches/rudder/7.0 Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants