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.ChoreService; 025import org.apache.hadoop.hbase.CoordinatedStateManager; 026import org.apache.hadoop.hbase.HBaseConfiguration; 027import org.apache.hadoop.hbase.Server; 028import org.apache.hadoop.hbase.ServerName; 029import org.apache.hadoop.hbase.client.ClusterConnection; 030import org.apache.hadoop.hbase.client.Connection; 031import org.apache.hadoop.hbase.io.util.MemorySizeUtil; 032import org.apache.hadoop.hbase.master.region.MasterRegion; 033import org.apache.hadoop.hbase.master.region.MasterRegionFactory; 034import org.apache.hadoop.hbase.procedure2.store.ProcedureStorePerformanceEvaluation; 035import org.apache.hadoop.hbase.regionserver.ChunkCreator; 036import org.apache.hadoop.hbase.regionserver.MemStoreLAB; 037import org.apache.hadoop.hbase.util.CommonFSUtils; 038import org.apache.hadoop.hbase.util.Pair; 039import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 040 041public class RegionProcedureStorePerformanceEvaluation 042 extends ProcedureStorePerformanceEvaluation<RegionProcedureStore> { 043 044 private static final class MockServer implements Server { 045 046 private final Configuration conf; 047 048 private final ServerName serverName = 049 ServerName.valueOf("localhost", 12345, System.currentTimeMillis()); 050 051 private volatile boolean abort = false; 052 053 public MockServer(Configuration conf) { 054 this.conf = conf; 055 } 056 057 @Override 058 public void abort(String why, Throwable e) { 059 abort = true; 060 } 061 062 @Override 063 public boolean isAborted() { 064 return abort; 065 } 066 067 @Override 068 public void stop(String why) { 069 } 070 071 @Override 072 public boolean isStopped() { 073 return false; 074 } 075 076 @Override 077 public Configuration getConfiguration() { 078 return conf; 079 } 080 081 @Override 082 public ZKWatcher getZooKeeper() { 083 throw new UnsupportedOperationException(); 084 } 085 086 @Override 087 public Connection getConnection() { 088 throw new UnsupportedOperationException(); 089 } 090 091 @Override 092 public Connection createConnection(Configuration conf) throws IOException { 093 throw new UnsupportedOperationException(); 094 } 095 096 @Override 097 public ClusterConnection getClusterConnection() { 098 throw new UnsupportedOperationException(); 099 } 100 101 @Override 102 public ServerName getServerName() { 103 return serverName; 104 } 105 106 @Override 107 public CoordinatedStateManager getCoordinatedStateManager() { 108 throw new UnsupportedOperationException(); 109 } 110 111 @Override 112 public ChoreService getChoreService() { 113 throw new UnsupportedOperationException(); 114 } 115 } 116 117 private MasterRegion region; 118 119 @Override 120 protected RegionProcedureStore createProcedureStore(Path storeDir) throws IOException { 121 Pair<Long, MemoryType> pair = MemorySizeUtil.getGlobalMemStoreSize(conf); 122 long globalMemStoreSize = pair.getFirst(); 123 boolean offheap = pair.getSecond() == MemoryType.NON_HEAP; 124 float poolSizePercentage = offheap ? 1.0F : 125 conf.getFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, MemStoreLAB.POOL_MAX_SIZE_DEFAULT); 126 float initialCountPercentage = 127 conf.getFloat(MemStoreLAB.CHUNK_POOL_INITIALSIZE_KEY, MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT); 128 int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT); 129 ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage, 130 initialCountPercentage, null); 131 conf.setBoolean(MasterRegionFactory.USE_HSYNC_KEY, "hsync".equals(syncType)); 132 CommonFSUtils.setRootDir(conf, storeDir); 133 MockServer server = new MockServer(conf); 134 region = MasterRegionFactory.create(server); 135 return new RegionProcedureStore(server, region, (fs, apth) -> { 136 }); 137 } 138 139 @Override 140 protected void printRawFormatResult(long timeTakenNs) { 141 System.out.println(String.format("RESULT [%s=%s, %s=%s, %s=%s, %s=%s, " + "total_time_ms=%s]", 142 NUM_PROCS_OPTION.getOpt(), numProcs, STATE_SIZE_OPTION.getOpt(), stateSize, 143 SYNC_OPTION.getOpt(), syncType, NUM_THREADS_OPTION.getOpt(), numThreads, timeTakenNs)); 144 } 145 146 @Override 147 protected void preWrite(long procId) throws IOException { 148 } 149 150 @Override 151 protected void postStop(RegionProcedureStore store) throws IOException { 152 region.close(true); 153 } 154 155 public static void main(String[] args) throws IOException { 156 RegionProcedureStorePerformanceEvaluation tool = 157 new RegionProcedureStorePerformanceEvaluation(); 158 tool.setConf(HBaseConfiguration.create()); 159 tool.run(args); 160 } 161}