Class CostBalancerStrategy
- java.lang.Object
-
- org.apache.druid.server.coordinator.balancer.CostBalancerStrategy
-
- All Implemented Interfaces:
BalancerStrategy
- Direct Known Subclasses:
CachingCostBalancerStrategy,DiskNormalizedCostBalancerStrategy
public class CostBalancerStrategy extends Object implements BalancerStrategy
-
-
Constructor Summary
Constructors Constructor Description CostBalancerStrategy(com.google.common.util.concurrent.ListeningExecutorService exec)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static doublecomputeJointSegmentsCost(org.apache.druid.timeline.DataSegment segment, Iterable<org.apache.druid.timeline.DataSegment> segmentSet)static doublecomputeJointSegmentsCost(org.apache.druid.timeline.DataSegment segmentA, org.apache.druid.timeline.DataSegment segmentB)This defines the unnormalized cost function between two segments.protected doublecomputePlacementCost(org.apache.druid.timeline.DataSegment proposalSegment, ServerHolder server)Computes the cost of placing a segment on this server.ServerHolderfindDestinationServerToMoveSegment(org.apache.druid.timeline.DataSegment segmentToMove, ServerHolder sourceServer, List<ServerHolder> serverHolders)Finds the best server from the list ofdestinationServersto load thesegmentToMove, if it is moved from thesourceServer.Iterator<ServerHolder>findServersToDropSegment(org.apache.druid.timeline.DataSegment segmentToDrop, List<ServerHolder> serverHolders)Finds the best servers to drop the given segment.Iterator<ServerHolder>findServersToLoadSegment(org.apache.druid.timeline.DataSegment segmentToLoad, List<ServerHolder> serverHolders)Finds the best servers to load the given segment.CoordinatorRunStatsgetStats()Returns the stats collected by the strategy.static doubleintervalCost(double x1, double y0, double y1)Computes the joint cost of two intervals X = [x_0 = 0, x_1) and Y = [y_0, y_1) cost(X, Y) = \int_{x_0}^{x_1} \int_{y_0}^{y_1} e^{-\lambda |x-y|}dxdy $$ lambda = 1 in this particular implementation Other values of lambda can be calculated by multiplying inputs by lambda and multiplying the result by 1 / lambda ^ 2 Interval start and end are all relative to x_0.static doubleintervalCost(org.joda.time.Interval intervalA, org.joda.time.Interval intervalB)
-
-
-
Method Detail
-
computeJointSegmentsCost
public static double computeJointSegmentsCost(org.apache.druid.timeline.DataSegment segment, Iterable<org.apache.druid.timeline.DataSegment> segmentSet)
-
computeJointSegmentsCost
public static double computeJointSegmentsCost(org.apache.druid.timeline.DataSegment segmentA, org.apache.druid.timeline.DataSegment segmentB)This defines the unnormalized cost function between two segments. See https://github.com/apache/druid/pull/2972 for more details about the cost function. intervalCost: segments close together are more likely to be queried together multiplier: if two segments belong to the same data source, they are more likely to be involved in the same queries- Parameters:
segmentA- The first DataSegment.segmentB- The second DataSegment.- Returns:
- the joint cost of placing the two DataSegments together on one node.
-
intervalCost
public static double intervalCost(org.joda.time.Interval intervalA, org.joda.time.Interval intervalB)
-
intervalCost
public static double intervalCost(double x1, double y0, double y1)Computes the joint cost of two intervals X = [x_0 = 0, x_1) and Y = [y_0, y_1) cost(X, Y) = \int_{x_0}^{x_1} \int_{y_0}^{y_1} e^{-\lambda |x-y|}dxdy $$ lambda = 1 in this particular implementation Other values of lambda can be calculated by multiplying inputs by lambda and multiplying the result by 1 / lambda ^ 2 Interval start and end are all relative to x_0. Therefore this function assumes x_0 = 0, x1 >= 0, and y1 > y0- Parameters:
x1- end of interval Xy0- start of interval Yy1- end o interval Y- Returns:
- joint cost of X and Y
-
findServersToLoadSegment
public Iterator<ServerHolder> findServersToLoadSegment(org.apache.druid.timeline.DataSegment segmentToLoad, List<ServerHolder> serverHolders)
Description copied from interface:BalancerStrategyFinds the best servers to load the given segment. This method can be used both for placing the first copy of a segment in a tier or a replica of an already available segment.- Specified by:
findServersToLoadSegmentin interfaceBalancerStrategy- Returns:
- Iterator over the best servers (in order of preference) to load the segment.
-
findDestinationServerToMoveSegment
public ServerHolder findDestinationServerToMoveSegment(org.apache.druid.timeline.DataSegment segmentToMove, ServerHolder sourceServer, List<ServerHolder> serverHolders)
Description copied from interface:BalancerStrategyFinds the best server from the list ofdestinationServersto load thesegmentToMove, if it is moved from thesourceServer.In order to avoid unnecessary moves when the segment is already optimally placed, include the
sourceServerin the list ofdestinationServers.- Specified by:
findDestinationServerToMoveSegmentin interfaceBalancerStrategy- Returns:
- The server to move to, or null if the segment is already optimally placed.
-
findServersToDropSegment
public Iterator<ServerHolder> findServersToDropSegment(org.apache.druid.timeline.DataSegment segmentToDrop, List<ServerHolder> serverHolders)
Description copied from interface:BalancerStrategyFinds the best servers to drop the given segment.- Specified by:
findServersToDropSegmentin interfaceBalancerStrategy- Returns:
- Iterator over the servers (in order of preference) to drop the segment
-
getStats
public CoordinatorRunStats getStats()
Description copied from interface:BalancerStrategyReturns the stats collected by the strategy.- Specified by:
getStatsin interfaceBalancerStrategy
-
computePlacementCost
protected double computePlacementCost(org.apache.druid.timeline.DataSegment proposalSegment, ServerHolder server)Computes the cost of placing a segment on this server.
-
-