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.MockNoopMasterServices; 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.Pair; 036 037public class RegionProcedureStorePerformanceEvaluation 038 extends ProcedureStorePerformanceEvaluation<RegionProcedureStore> { 039 040 private static final class DummyServer extends MockNoopMasterServices { 041 042 private final ServerName serverName = 043 ServerName.valueOf("localhost", 12345, EnvironmentEdgeManager.currentTime()); 044 045 public DummyServer(Configuration conf) { 046 super(conf); 047 } 048 049 @Override 050 public ServerName getServerName() { 051 return serverName; 052 } 053 } 054 055 private MasterRegion region; 056 057 @Override 058 protected RegionProcedureStore createProcedureStore(Path storeDir) throws IOException { 059 Pair<Long, MemoryType> pair = MemorySizeUtil.getGlobalMemStoreSize(conf); 060 long globalMemStoreSize = pair.getFirst(); 061 boolean offheap = pair.getSecond() == MemoryType.NON_HEAP; 062 float poolSizePercentage = offheap 063 ? 1.0F 064 : conf.getFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, MemStoreLAB.POOL_MAX_SIZE_DEFAULT); 065 float initialCountPercentage = 066 conf.getFloat(MemStoreLAB.CHUNK_POOL_INITIALSIZE_KEY, MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT); 067 int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT); 068 float indexChunkSizePercent = conf.getFloat(MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_KEY, 069 MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT); 070 ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage, 071 initialCountPercentage, null, indexChunkSizePercent); 072 conf.setBoolean(MasterRegionFactory.USE_HSYNC_KEY, "hsync".equals(syncType)); 073 CommonFSUtils.setRootDir(conf, storeDir); 074 DummyServer server = new DummyServer(conf); 075 region = MasterRegionFactory.create(server); 076 return new RegionProcedureStore(server, region, (fs, apth) -> { 077 }); 078 } 079 080 @Override 081 protected void printRawFormatResult(long timeTakenNs) { 082 System.out.println(String.format("RESULT [%s=%s, %s=%s, %s=%s, %s=%s, " + "total_time_ms=%s]", 083 NUM_PROCS_OPTION.getOpt(), numProcs, STATE_SIZE_OPTION.getOpt(), stateSize, 084 SYNC_OPTION.getOpt(), syncType, NUM_THREADS_OPTION.getOpt(), numThreads, timeTakenNs)); 085 } 086 087 @Override 088 protected void preWrite(long procId) throws IOException { 089 } 090 091 @Override 092 protected void postStop(RegionProcedureStore store) throws IOException { 093 region.close(true); 094 } 095 096 public static void main(String[] args) throws IOException { 097 RegionProcedureStorePerformanceEvaluation tool = 098 new RegionProcedureStorePerformanceEvaluation(); 099 tool.setConf(HBaseConfiguration.create()); 100 tool.run(args); 101 } 102}