forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalized Cost Balancer (apache#3632)
* Normalized Cost Balancer * Adding documentation and renaming to use diskNormalizedCostBalancer * Remove balancer from the strings * Update docs and include random cost balancer * Fix checkstyle issues
- Loading branch information
Showing
17 changed files
with
460 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
server/src/main/java/io/druid/server/coordinator/DiskNormalizedCostBalancerStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.druid.server.coordinator; | ||
|
||
import com.google.common.util.concurrent.ListeningExecutorService; | ||
import io.druid.timeline.DataSegment; | ||
|
||
public class DiskNormalizedCostBalancerStrategy extends CostBalancerStrategy | ||
{ | ||
public DiskNormalizedCostBalancerStrategy(ListeningExecutorService exec) | ||
{ | ||
super(exec); | ||
} | ||
|
||
/** | ||
* Averages the cost obtained from CostBalancerStrategy. Also the costs are weighted according to their usage ratios. | ||
* This ensures that all the hosts will have the same % disk utilization. | ||
*/ | ||
@Override | ||
protected double computeCost( | ||
final DataSegment proposalSegment, final ServerHolder server, final boolean includeCurrentServer | ||
) | ||
{ | ||
double cost = super.computeCost(proposalSegment, server, includeCurrentServer); | ||
|
||
if(cost == Double.POSITIVE_INFINITY){ | ||
return cost; | ||
} | ||
|
||
int nSegments = 1; | ||
if(server.getServer().getSegments().size() > 0) | ||
{ | ||
nSegments = server.getServer().getSegments().size(); | ||
} | ||
|
||
double normalizedCost = cost/nSegments; | ||
double usageRatio = (double)server.getServer().getCurrSize()/(double)server.getServer().getMaxSize(); | ||
|
||
return normalizedCost*usageRatio; | ||
} | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
.../src/main/java/io/druid/server/coordinator/DiskNormalizedCostBalancerStrategyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.druid.server.coordinator; | ||
|
||
import com.google.common.util.concurrent.ListeningExecutorService; | ||
|
||
public class DiskNormalizedCostBalancerStrategyFactory implements BalancerStrategyFactory | ||
{ | ||
@Override | ||
public BalancerStrategy createBalancerStrategy(ListeningExecutorService exec) | ||
{ | ||
return new DiskNormalizedCostBalancerStrategy(exec); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.