View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.master.balancer;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.hadoop.hbase.testclassification.MediumTests;
23  import org.junit.After;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  @Category({MediumTests.class})
29  public class TestStochasticLoadBalancer2 extends BalancerTestBase {
30    private static final Log LOG = LogFactory.getLog(TestStochasticLoadBalancer2.class);
31  
32    @Before
33    public void before() {
34      conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 1.0f);
35      conf.setLong(StochasticLoadBalancer.MAX_STEPS_KEY, 2000000L);
36      conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0);
37      conf.setLong("hbase.master.balancer.stochastic.maxRunningTime", 90 * 1000); // 90 sec
38      conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.05f);
39      loadBalancer.setConf(conf);
40    }
41  
42    @After
43    public void after() {
44      // reset config to make sure balancer run
45      conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f);
46      loadBalancer.setConf(conf);
47    }
48  
49    @Test (timeout = 800000)
50    public void testRegionReplicasOnMidCluster() {
51      conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0);
52      TestStochasticLoadBalancer.loadBalancer.setConf(conf);
53      int numNodes = 200;
54      int numRegions = 40 * 200;
55      int replication = 3; // 3 replicas per region
56      int numRegionsPerServer = 30; //all regions are mostly balanced
57      int numTables = 10;
58      testWithCluster(numNodes, numRegions, numRegionsPerServer, replication, numTables, true, true);
59    }
60  
61    @Test (timeout = 800000)
62    public void testRegionReplicasOnLargeCluster() {
63      conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 1.0f);
64      conf.setLong(StochasticLoadBalancer.MAX_STEPS_KEY, 2000000L);
65      conf.setLong("hbase.master.balancer.stochastic.maxRunningTime", 90 * 1000); // 90 sec
66      conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0);
67      loadBalancer.setConf(conf);
68      int numNodes = 1000;
69      int numRegions = 20 * numNodes; // 20 * replication regions per RS
70      int numRegionsPerServer = 19; // all servers except one
71      int numTables = 100;
72      int replication = 3;
73      testWithCluster(numNodes, numRegions, numRegionsPerServer, replication, numTables, true, true);
74    }
75  
76    @Test (timeout = 800000)
77    public void testRegionReplicasOnMidClusterHighReplication() {
78      conf.setLong(StochasticLoadBalancer.MAX_STEPS_KEY, 4000000L);
79      conf.setLong("hbase.master.balancer.stochastic.maxRunningTime", 120 * 1000); // 120 sec
80      conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0);
81      conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 1.0f);
82      loadBalancer.setConf(conf);
83      int numNodes = 80;
84      int numRegions = 6 * numNodes;
85      int replication = 80; // 80 replicas per region, one for each server
86      int numRegionsPerServer = 5;
87      int numTables = 10;
88      testWithCluster(numNodes, numRegions, numRegionsPerServer, replication, numTables, false, true);
89    }
90  
91    @Test (timeout = 800000)
92    public void testRegionReplicationOnMidClusterReplicationGreaterThanNumNodes() {
93      conf.setLong("hbase.master.balancer.stochastic.maxRunningTime", 120 * 1000); // 120 sec
94      conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0);
95      conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 1.0f);
96      loadBalancer.setConf(conf);
97      int numNodes = 40;
98      int numRegions = 6 * 50;
99      int replication = 50; // 50 replicas per region, more than numNodes
100     int numRegionsPerServer = 6;
101     int numTables = 10;
102     testWithCluster(numNodes, numRegions, numRegionsPerServer, replication, numTables, true, false);
103   }
104 }