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 #7541: Major performance hit in promise generation for unused inventories fetch #985

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -61,7 +61,6 @@ import com.normation.rudder.domain.reports.NodeAndConfigId
case class InterpolationContext(
nodeInfo : NodeInfo
, policyServerInfo: NodeInfo
, inventory : NodeInventory
//environment variable for that server
//must be a case insensitive Map !!!!
, nodeContext : TreeMap[String, Variable]
Expand All @@ -83,7 +82,6 @@ object InterpolationContext {
def apply(
nodeInfo : NodeInfo
, policyServerInfo: NodeInfo
, inventory : NodeInventory
//environment variable for that server
//must be a case insensitive Map !!!!
, nodeContext : Map[String, Variable]
Expand All @@ -95,7 +93,7 @@ object InterpolationContext {
//for ex: param a => param b => param c => ..... => param a
//should not be evaluated
, depth : Int = 0
) = new InterpolationContext(nodeInfo, policyServerInfo, inventory, TreeMap(nodeContext.toSeq:_*), parameters, depth)
) = new InterpolationContext(nodeInfo, policyServerInfo, TreeMap(nodeContext.toSeq:_*), parameters, depth)
}

/**
Expand Down
Expand Up @@ -99,19 +99,31 @@ trait DeploymentService extends Loggable {

val result = for {
//fetch all - yep, memory is cheap... (TODO: size of that for 1000 nodes, 100 rules, 100 directives, 100 groups ?)
allRules <- findDependantRules() ?~! "Could not find dependant rules"
allNodeInfos <- getAllNodeInfos ?~! "Could not get Node Infos"
allInventories <- getAllInventories ?~! "Could not get Node inventories"
directiveLib <- getDirectiveLibrary() ?~! "Could not get the directive library"
groupLib <- getGroupLibrary() ?~! "Could not get the group library"
allParameters <- getAllGlobalParameters ?~! "Could not get global parameters"

allRules <- findDependantRules() ?~! "Could not find dependant rules"
fetch1Time = System.currentTimeMillis
_ = logger.trace(s"Fetched rules in ${fetch1Time-initialTime}ms")
allNodeInfos <- getAllNodeInfos ?~! "Could not get Node Infos"
fetch2Time = System.currentTimeMillis
_ = logger.trace(s"Fetched node infos in ${fetch2Time-fetch1Time}ms")
directiveLib <- getDirectiveLibrary() ?~! "Could not get the directive library"
fetch3Time = System.currentTimeMillis
_ = logger.trace(s"Fetched directives in ${fetch3Time-fetch2Time}ms")
groupLib <- getGroupLibrary() ?~! "Could not get the group library"
fetch4Time = System.currentTimeMillis
_ = logger.trace(s"Fetched groups in ${fetch4Time-fetch3Time}ms")
allParameters <- getAllGlobalParameters ?~! "Could not get global parameters"
fetch5Time = System.currentTimeMillis
_ = logger.trace(s"Fetched global parameters in ${fetch4Time-fetch3Time}ms")
agentRunInterval = getAgentRunInterval()
agentRunSplaytime <- getAgentRunSplaytime() ?~! "Could not get agent run splaytime"
agentRunStartMinute <- getAgentRunStartMinute() ?~! "Could not get agent run start time (minute)"
agentRunStartHour <- getAgentRunStartHour() ?~! "Could not get agent run start time (hour)"
fetch6Time = System.currentTimeMillis
_ = logger.trace(s"Fetched run infos in ${fetch4Time-fetch3Time}ms")

timeFetchAll = (System.currentTimeMillis - initialTime)
_ = logger.debug(s"All relevant information fetched in ${timeFetchAll}ms, start names historization.")
timeFetchAll = (System.currentTimeMillis - initialTime)
_ = logger.debug(s"All relevant information fetched in ${timeFetchAll}ms, start names historization.")

historizeTime = System.currentTimeMillis
historize <- historizeData(allRules, directiveLib, groupLib, allNodeInfos, agentRunInterval, agentRunSplaytime, agentRunStartHour, agentRunStartMinute)
Expand All @@ -134,7 +146,6 @@ trait DeploymentService extends Loggable {
config <- buildNodeConfigurations(
ruleVals
, allNodeInfos
, allInventories
, groupLib
, allParameters
, globalSystemVariables
Expand Down Expand Up @@ -250,7 +261,6 @@ trait DeploymentService extends Loggable {
def buildNodeConfigurations(
ruleVals : Seq[RuleVal]
, allNodeInfos : Map[NodeId, NodeInfo]
, allInventories : Map[NodeId, NodeInventory]
, groupLib : FullNodeGroupCategory
, parameters : Seq[GlobalParameter]
, globalSystemVariable : Map[String, Variable]
Expand Down Expand Up @@ -497,7 +507,6 @@ trait DeploymentService_buildNodeConfigurations extends DeploymentService with L
private[this] def buildInterpolationContext(
nodeIds : Set[NodeId]
, allNodeInfos : Map[NodeId, NodeInfo]
, allInventories : Map[NodeId, NodeInventory]
, parameters : Map[ParameterName, InterpolationContext => Box[String]]
, globalSystemVariables : Map[String, Variable]
, globalAgentRun : AgentRunInterval
Expand All @@ -507,15 +516,13 @@ trait DeploymentService_buildNodeConfigurations extends DeploymentService with L
(nodeIds.flatMap { nodeId:NodeId =>
(for {
nodeInfo <- Box(allNodeInfos.get(nodeId)) ?~! s"Node with ID ${nodeId.value} was not found"
inventory <- Box(allInventories.get(nodeId)) ?~! s"Inventory for node with ID ${nodeId.value} was not found"
policyServer <- Box(allNodeInfos.get(nodeInfo.policyServerId)) ?~! s"Node with ID ${nodeId.value} was not found"

nodeContext <- systemVarService.getSystemVariables(nodeInfo, allNodeInfos, globalSystemVariables, globalAgentRun, globalComplianceMode : ComplianceMode)
} yield {
(nodeId, InterpolationContext(
nodeInfo
, policyServer
, inventory
, nodeContext
, parameters
)
Expand Down Expand Up @@ -549,7 +556,6 @@ trait DeploymentService_buildNodeConfigurations extends DeploymentService with L
override def buildNodeConfigurations(
ruleVals : Seq[RuleVal]
, allNodeInfos : Map[NodeId, NodeInfo]
, allInventories : Map[NodeId, NodeInventory]
, groupLib : FullNodeGroupCategory
, parameters : Seq[GlobalParameter]
, globalSystemVariables : Map[String, Variable]
Expand Down Expand Up @@ -635,7 +641,6 @@ trait DeploymentService_buildNodeConfigurations extends DeploymentService with L
buildInterpolationContext(
policyDraftByNode.keySet
, allNodeInfos
, allInventories
, interpolatedParameters
, globalSystemVariables
, globalAgentRun
Expand Down
Expand Up @@ -161,7 +161,6 @@ class TestNodeAndParameterLookup extends Specification {
val context = InterpolationContext(
parameters = Map()
, nodeInfo = node1
, inventory = nodeInventory1
, policyServerInfo= root
//environment variable for that server
, nodeContext = Map()
Expand Down Expand Up @@ -551,4 +550,4 @@ class TestNodeAndParameterLookup extends Specification {

}

}
}