Class MinimumInstanceChecker
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidChecks all EC2 cloud templates and provisions agents to meet minimum instance requirements.static intcountAgentsRunningWorkFor(EC2Cloud cloud, Label label) static intcountCurrentNumberOfAgents(SlaveTemplate agentTemplate) static intcountCurrentNumberOfProvisioningAgents(SlaveTemplate agentTemplate) static intcountCurrentNumberOfProvisioningAgentsForLabel(EC2Cloud cloud, Label label) static intcountCurrentNumberOfSpareAgents(SlaveTemplate agentTemplate) static intcountCurrentNumberOfSpareAgentsForLabel(EC2Cloud cloud, Label label) static intcountQueueItemsForAgentTemplate(SlaveTemplate agentTemplate) static intcountQueueItemsRequesting(Label label) static voidstatic booleanisSpareStillWanted(EC2Cloud cloud, EC2Computer computer) Whether the hot spare prediction for a label is still counting on this agent, which is the question the idle timeout has to ask before reclaiming it.static booleankeepsWarmInstancesNow(SlaveTemplate template) static booleanminimumInstancesActive(MinimumNumberOfInstancesTimeRangeConfig minimumNumberOfInstancesTimeRangeConfig) static voidSchedules a minimum-instance check to run asynchronously.
-
Field Details
-
clock
-
-
Constructor Details
-
MinimumInstanceChecker
public MinimumInstanceChecker()
-
-
Method Details
-
scheduleCheck
public static void scheduleCheck()Schedules a minimum-instance check to run asynchronously. Use this instead ofcheckForMinimumInstances()when the caller must return immediately (e.g. taskAccepted).Requests that arrive while one is already waiting are dropped: the queued check has not looked at Jenkins yet, so it will see everything they would have asked about. Without this, a burst of builds starting at once would queue one redundant pass per build behind the single checker thread.
-
countCurrentNumberOfAgents
-
countCurrentNumberOfSpareAgents
-
countCurrentNumberOfProvisioningAgents
- Returns:
- the number of agents of this template that exist but cannot take work yet. Counted
from attachment rather than from the launcher starting, for the reason given on
countCurrentNumberOfProvisioningAgentsForLabel(hudson.plugins.ec2.EC2Cloud, hudson.model.Label).
-
countQueueItemsForAgentTemplate
-
countCurrentNumberOfSpareAgentsForLabel
-
keepsWarmInstancesNow
- Returns:
- whether a template may be holding instances nothing has asked for at this moment. Only apply minimum number of instances during specific time range is how an admin pays for warm capacity only when it is worth having, so a hot spare rule honours it instead of quietly putting the template back on the clock around the clock. The schedule stays a property of the template, which is what lets one label be served by a template per shift.
-
isSpareStillWanted
Whether the hot spare prediction for a label is still counting on this agent, which is the question the idle timeout has to ask before reclaiming it. Terminating a spare the target wants pays for the same capacity twice - once for the instance thrown away, again for the one the next pass launches in its place - and leaves a build waiting for the boot in between.The spares are ranked by how long each has been idle and the freshest
targetof them are kept, so several agents asking at once agree on which are the extras and exactly the surplus is released. Releasing the longest-idle first keeps the behaviour of an idle timeout: the agent that has been sitting unused the longest is the one that goes.The agent being asked about is included whether or not the counted set has caught up with it, because the comparison is meaningless if the pool it is ranked against excludes it.
An agent can serve several labels, each with a target of its own, so the question is asked of every label it could take work for: it is surplus only once none of them is counting on it.
- Returns:
- true when some label wants this agent kept warm, false when it is surplus to all of them or is not warm capacity at all.
-
countCurrentNumberOfProvisioningAgentsForLabel
public static int countCurrentNumberOfProvisioningAgentsForLabel(@NonNull EC2Cloud cloud, @NonNull Label label) - Returns:
- the number of agents of the label group that exist but cannot take work yet.
An agent is counted from the moment it is attached rather than from the moment its launcher starts, because
Computer.isConnecting()is false for the gap in between and two passes falling either side of that gap would launch the same shortfall twice. Passes are triggered by builds queueing and starting, so they do arrive in quick succession. An agent that never comes up is dealt with by its grace period.
-
countAgentsRunningWorkFor
- Returns:
- the number of agents running a build that asked for this label. They are not spares,
which is why a spare taken by a build is replaced, but they do say the label is in use.
What the build asked for is the measure, not what the agent happens to be able to run: an agent serving a branch build on a template that also carries the pull request label says nothing about how much pull request capacity to keep warm.
-
countQueueItemsRequesting
- Returns:
- the number of buildable queue items waiting for exactly this label. An item waiting for a different label is another label's demand, even when one template could serve both.
-
checkForMinimumInstances
public static void checkForMinimumInstances()Checks all EC2 cloud templates and provisions agents to meet minimum instance requirements. Synchronized to prevent concurrent provisioning decisions that could lead to over-provisioning when multiple agents accept tasks simultaneously.- See Also:
-
minimumInstancesActive
public static boolean minimumInstancesActive(MinimumNumberOfInstancesTimeRangeConfig minimumNumberOfInstancesTimeRangeConfig) -
discardIdleInstances
- Throws:
Exception
-