HDDS-1130. Make BenchMarkBlockManager multi-threaded. Contributed by Lokesh Jain.

This commit is contained in:
Yiqun Lin 2019-02-20 10:45:51 +08:00
parent 51950f149e
commit 1d30fd94c6
1 changed files with 49 additions and 32 deletions

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.ozone.genesis; package org.apache.hadoop.ozone.genesis;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdds.HddsConfigKeys; import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor; import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
@ -46,6 +47,7 @@ import java.io.IOException;
import java.util.UUID; import java.util.UUID;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DB_CACHE_SIZE_DEFAULT; import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DB_CACHE_SIZE_DEFAULT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DB_CACHE_SIZE_MB; import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DB_CACHE_SIZE_MB;
@ -59,9 +61,16 @@ import static org.apache.hadoop.ozone.OzoneConsts.SCM_PIPELINE_DB;
@State(Scope.Thread) @State(Scope.Thread)
public class BenchMarkBlockManager { public class BenchMarkBlockManager {
private StorageContainerManager scm; private static String testDir;
private PipelineManager pipelineManager; private static StorageContainerManager scm;
private BlockManager blockManager; private static PipelineManager pipelineManager;
private static BlockManager blockManager;
private static ReentrantLock lock = new ReentrantLock();
@Param({"1", "10", "100", "1000", "10000", "100000"})
private static int numPipelines;
@Param({"3", "10", "100"})
private static int numContainersPerPipeline;
private static StorageContainerManager getScm(OzoneConfiguration conf, private static StorageContainerManager getScm(OzoneConfiguration conf,
SCMConfigurator configurator) throws IOException, SCMConfigurator configurator) throws IOException,
@ -80,46 +89,53 @@ public class BenchMarkBlockManager {
} }
@Setup(Level.Trial) @Setup(Level.Trial)
public void initialize() public static void initialize()
throws IOException, AuthenticationException, InterruptedException { throws IOException, AuthenticationException, InterruptedException {
OzoneConfiguration conf = new OzoneConfiguration(); try {
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, lock.lock();
GenesisUtil.getTempPath().resolve(RandomStringUtils.randomNumeric(7)) if (scm == null) {
.toString()); OzoneConfiguration conf = new OzoneConfiguration();
conf.setInt(OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT, 100); testDir = GenesisUtil.getTempPath()
final File metaDir = ServerUtils.getScmDbDir(conf); .resolve(RandomStringUtils.randomNumeric(7)).toString();
final File pipelineDBPath = new File(metaDir, SCM_PIPELINE_DB); conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir);
int cacheSize = conf.getInt(OZONE_SCM_DB_CACHE_SIZE_MB, conf.setInt(OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT,
OZONE_SCM_DB_CACHE_SIZE_DEFAULT); numContainersPerPipeline);
MetadataStore pipelineStore = final File metaDir = ServerUtils.getScmDbDir(conf);
MetadataStoreBuilder.newBuilder() final File pipelineDBPath = new File(metaDir, SCM_PIPELINE_DB);
.setCreateIfMissing(true) int cacheSize = conf.getInt(OZONE_SCM_DB_CACHE_SIZE_MB,
.setConf(conf) OZONE_SCM_DB_CACHE_SIZE_DEFAULT);
.setDbFile(pipelineDBPath) MetadataStore pipelineStore =
.setCacheSize(cacheSize * OzoneConsts.MB) MetadataStoreBuilder.newBuilder().setCreateIfMissing(true)
.build(); .setConf(conf).setDbFile(pipelineDBPath)
addPipelines(100, ReplicationFactor.THREE, pipelineStore); .setCacheSize(cacheSize * OzoneConsts.MB).build();
pipelineStore.close(); addPipelines(ReplicationFactor.THREE,
scm = getScm(conf, new SCMConfigurator()); pipelineStore);
pipelineManager = scm.getPipelineManager(); pipelineStore.close();
for (Pipeline pipeline : pipelineManager scm = getScm(conf, new SCMConfigurator());
.getPipelines(ReplicationType.RATIS, ReplicationFactor.THREE)) { pipelineManager = scm.getPipelineManager();
pipelineManager.openPipeline(pipeline.getId()); for (Pipeline pipeline : pipelineManager
.getPipelines(ReplicationType.RATIS, ReplicationFactor.THREE)) {
pipelineManager.openPipeline(pipeline.getId());
}
blockManager = scm.getScmBlockManager();
scm.getEventQueue().fireEvent(SCMEvents.CHILL_MODE_STATUS, false);
Thread.sleep(1000);
}
} finally {
lock.unlock();
} }
blockManager = scm.getScmBlockManager();
scm.getEventQueue().fireEvent(SCMEvents.CHILL_MODE_STATUS, false);
Thread.sleep(1000);
} }
@Setup(Level.Trial) @Setup(Level.Trial)
public void tearDown() { public static void tearDown() {
if (scm != null) { if (scm != null) {
scm.stop(); scm.stop();
scm.join(); scm.join();
FileUtil.fullyDelete(new File(testDir));
} }
} }
private void addPipelines(int numPipelines, ReplicationFactor factor, private static void addPipelines(ReplicationFactor factor,
MetadataStore pipelineStore) throws IOException { MetadataStore pipelineStore) throws IOException {
List<DatanodeDetails> nodes = new ArrayList<>(); List<DatanodeDetails> nodes = new ArrayList<>();
for (int i = 0; i < factor.getNumber(); i++) { for (int i = 0; i < factor.getNumber(); i++) {
@ -140,6 +156,7 @@ public class BenchMarkBlockManager {
} }
} }
@Threads(4)
@Benchmark @Benchmark
public void allocateBlockBenchMark(BenchMarkBlockManager state, public void allocateBlockBenchMark(BenchMarkBlockManager state,
Blackhole bh) throws IOException { Blackhole bh) throws IOException {