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;
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.HBaseConfiguration;
025import org.apache.hadoop.hbase.ServerName;
026import org.apache.hadoop.hbase.io.util.MemorySizeUtil;
027import org.apache.hadoop.hbase.master.region.MasterRegion;
028import org.apache.hadoop.hbase.master.region.MasterRegionFactory;
029import org.apache.hadoop.hbase.procedure2.store.ProcedureStorePerformanceEvaluation;
030import org.apache.hadoop.hbase.regionserver.ChunkCreator;
031import org.apache.hadoop.hbase.regionserver.MemStoreLAB;
032import org.apache.hadoop.hbase.util.CommonFSUtils;
033import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
034import org.apache.hadoop.hbase.util.MockServer;
035import org.apache.hadoop.hbase.util.Pair;
036
037public class RegionProcedureStorePerformanceEvaluation
038  extends ProcedureStorePerformanceEvaluation<RegionProcedureStore> {
039
040  private static final class DummyServer extends MockServer {
041
042    private final Configuration conf;
043
044    private final ServerName serverName =
045      ServerName.valueOf("localhost", 12345, EnvironmentEdgeManager.currentTime());
046
047    public DummyServer(Configuration conf) {
048      this.conf = conf;
049    }
050
051    @Override
052    public Configuration getConfiguration() {
053      return conf;
054    }
055
056    @Override
057    public ServerName getServerName() {
058      return serverName;
059    }
060  }
061
062  private MasterRegion region;
063
064  @Override
065  protected RegionProcedureStore createProcedureStore(Path storeDir) throws IOException {
066    Pair<Long, MemoryType> pair = MemorySizeUtil.getGlobalMemStoreSize(conf);
067    long globalMemStoreSize = pair.getFirst();
068    boolean offheap = pair.getSecond() == MemoryType.NON_HEAP;
069    float poolSizePercentage = offheap
070      ? 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}