001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.procedure2.store.region;
019
020import java.io.IOException;
021import java.lang.management.MemoryType;
022
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.fs.Path;
025import org.apache.hadoop.hbase.HBaseConfiguration;
026import org.apache.hadoop.hbase.ServerName;
027import org.apache.hadoop.hbase.io.util.MemorySizeUtil;
028import org.apache.hadoop.hbase.master.region.MasterRegion;
029import org.apache.hadoop.hbase.master.region.MasterRegionFactory;
030import org.apache.hadoop.hbase.procedure2.store.ProcedureStorePerformanceEvaluation;
031import org.apache.hadoop.hbase.regionserver.ChunkCreator;
032import org.apache.hadoop.hbase.regionserver.MemStoreLAB;
033import org.apache.hadoop.hbase.util.CommonFSUtils;
034import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
035import org.apache.hadoop.hbase.util.MockServer;
036import org.apache.hadoop.hbase.util.Pair;
037
038public class RegionProcedureStorePerformanceEvaluation
039  extends ProcedureStorePerformanceEvaluation<RegionProcedureStore> {
040
041  private static final class DummyServer extends MockServer {
042
043    private final Configuration conf;
044
045    private final ServerName serverName =
046      ServerName.valueOf("localhost", 12345, EnvironmentEdgeManager.currentTime());
047
048    public DummyServer(Configuration conf) {
049      this.conf = conf;
050    }
051
052    @Override
053    public Configuration getConfiguration() {
054      return conf;
055    }
056
057    @Override
058    public ServerName getServerName() {
059      return serverName;
060    }
061  }
062
063  private MasterRegion region;
064
065  @Override
066  protected RegionProcedureStore createProcedureStore(Path storeDir) throws IOException {
067    Pair<Long, MemoryType> pair = MemorySizeUtil.getGlobalMemStoreSize(conf);
068    long globalMemStoreSize = pair.getFirst();
069    boolean offheap = pair.getSecond() == MemoryType.NON_HEAP;
070    float poolSizePercentage = offheap ? 1.0F :
071      conf.getFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, MemStoreLAB.POOL_MAX_SIZE_DEFAULT);
072    float initialCountPercentage =
073      conf.getFloat(MemStoreLAB.CHUNK_POOL_INITIALSIZE_KEY, MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT);
074    int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT);
075    float indexChunkSizePercent = conf.getFloat(MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_KEY,
076      MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
077    ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,
078      initialCountPercentage, null, indexChunkSizePercent);
079    conf.setBoolean(MasterRegionFactory.USE_HSYNC_KEY, "hsync".equals(syncType));
080    CommonFSUtils.setRootDir(conf, storeDir);
081    DummyServer server = new DummyServer(conf);
082    region = MasterRegionFactory.create(server);
083    return new RegionProcedureStore(server, region, (fs, apth) -> {
084    });
085  }
086
087  @Override
088  protected void printRawFormatResult(long timeTakenNs) {
089    System.out.println(String.format("RESULT [%s=%s, %s=%s, %s=%s, %s=%s, " + "total_time_ms=%s]",
090      NUM_PROCS_OPTION.getOpt(), numProcs, STATE_SIZE_OPTION.getOpt(), stateSize,
091      SYNC_OPTION.getOpt(), syncType, NUM_THREADS_OPTION.getOpt(), numThreads, timeTakenNs));
092  }
093
094  @Override
095  protected void preWrite(long procId) throws IOException {
096  }
097
098  @Override
099  protected void postStop(RegionProcedureStore store) throws IOException {
100    region.close(true);
101  }
102
103  public static void main(String[] args) throws IOException {
104    RegionProcedureStorePerformanceEvaluation tool =
105      new RegionProcedureStorePerformanceEvaluation();
106    tool.setConf(HBaseConfiguration.create());
107    tool.run(args);
108  }
109}