-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement MaxCapacityUsageInstanceConstraint soft constraint (#463)
The constraint evaluates the score by checking the max used capacity key out of all the capacity keys. The higher the maximum usage value for the capacity key, the lower the score will be, implying that it is that much less desirable to assign anything on the given node. It is a greedy approach since it evaluates only the most used capacity key.
- Loading branch information
Showing
6 changed files
with
113 additions
and
5 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
47 changes: 47 additions & 0 deletions
47
...che/helix/controller/rebalancer/waged/constraints/MaxCapacityUsageInstanceConstraint.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,47 @@ | ||
package org.apache.helix.controller.rebalancer.waged.constraints; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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. | ||
*/ | ||
|
||
import org.apache.helix.controller.rebalancer.waged.model.AssignableNode; | ||
import org.apache.helix.controller.rebalancer.waged.model.AssignableReplica; | ||
import org.apache.helix.controller.rebalancer.waged.model.ClusterContext; | ||
|
||
/** | ||
* The constraint evaluates the score by checking the max used capacity key out of all the capacity | ||
* keys. | ||
* The higher the maximum usage value for the capacity key, the lower the score will be, implying | ||
* that it is that much less desirable to assign anything on the given node. | ||
* It is a greedy approach since it evaluates only on the most used capacity key. | ||
*/ | ||
class MaxCapacityUsageInstanceConstraint extends SoftConstraint { | ||
private static final float MIN_SCORE = 0; | ||
private static final float MAX_SCORE = 1; | ||
|
||
MaxCapacityUsageInstanceConstraint() { | ||
super(MAX_SCORE, MIN_SCORE); | ||
} | ||
|
||
@Override | ||
protected float getAssignmentScore(AssignableNode node, AssignableReplica replica, | ||
ClusterContext clusterContext) { | ||
float maxCapacityUsage = node.getHighestCapacityUtilization(); | ||
return 1.0f - maxCapacityUsage / 2.0f; | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
...helix/controller/rebalancer/waged/constraints/TestMaxCapacityUsageInstanceConstraint.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,56 @@ | ||
package org.apache.helix.controller.rebalancer.waged.constraints; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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. | ||
*/ | ||
|
||
import static org.mockito.Mockito.CALLS_REAL_METHODS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.apache.helix.controller.rebalancer.waged.model.AssignableNode; | ||
import org.apache.helix.controller.rebalancer.waged.model.AssignableReplica; | ||
import org.apache.helix.controller.rebalancer.waged.model.ClusterContext; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestMaxCapacityUsageInstanceConstraint { | ||
private AssignableReplica _testReplica; | ||
private AssignableNode _testNode; | ||
private ClusterContext _clusterContext; | ||
private final SoftConstraint _constraint = new MaxCapacityUsageInstanceConstraint(); | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
_testNode = mock(AssignableNode.class, CALLS_REAL_METHODS); | ||
_testReplica = mock(AssignableReplica.class); | ||
_clusterContext = mock(ClusterContext.class); | ||
} | ||
|
||
@Test | ||
public void testGetNormalizedScore() { | ||
when(_testNode.getHighestCapacityUtilization()).thenReturn(0.8f); | ||
float score = | ||
_constraint.getAssignmentScore(_testNode, _testReplica, _clusterContext); | ||
Assert.assertEquals(score, 0.6f); | ||
float normalizedScore = | ||
_constraint.getAssignmentNormalizedScore(_testNode, _testReplica, _clusterContext); | ||
Assert.assertEquals(normalizedScore, 0.6f); | ||
} | ||
} |