From 084b6a6751dd203de1c7f3c65077ca72f1d83632 Mon Sep 17 00:00:00 2001 From: Yiqun Lin Date: Fri, 15 Feb 2019 14:23:34 +0800 Subject: [PATCH] HDDS-1099. Genesis benchmark for ozone key creation in OM. Contributed by Bharat Viswanadham. --- hadoop-ozone/tools/pom.xml | 9 +- .../genesis/BenchMarkOMKeyAllocation.java | 135 ++++++++++++++++++ .../apache/hadoop/ozone/genesis/Genesis.java | 1 + 3 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genesis/BenchMarkOMKeyAllocation.java diff --git a/hadoop-ozone/tools/pom.xml b/hadoop-ozone/tools/pom.xml index 95bef70bca..aeff0f7b30 100644 --- a/hadoop-ozone/tools/pom.xml +++ b/hadoop-ozone/tools/pom.xml @@ -29,6 +29,10 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> jar + + org.apache.hadoop + hadoop-ozone-ozone-manager + org.apache.hadoop hadoop-ozone-common @@ -78,11 +82,6 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> 2.15.0 test - - org.apache.hadoop - hadoop-ozone-ozone-manager - 0.4.0-SNAPSHOT - diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genesis/BenchMarkOMKeyAllocation.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genesis/BenchMarkOMKeyAllocation.java new file mode 100644 index 0000000000..fbb686a475 --- /dev/null +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genesis/BenchMarkOMKeyAllocation.java @@ -0,0 +1,135 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.ozone.genesis; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.RandomUtils; +import org.apache.hadoop.hdds.client.BlockID; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.ozone.om.BucketManager; +import org.apache.hadoop.ozone.om.BucketManagerImpl; +import org.apache.hadoop.ozone.om.KeyManager; +import org.apache.hadoop.ozone.om.KeyManagerImpl; +import org.apache.hadoop.ozone.om.OMConfigKeys; +import org.apache.hadoop.ozone.om.OmMetadataManagerImpl; +import org.apache.hadoop.ozone.om.VolumeManager; +import org.apache.hadoop.ozone.om.VolumeManagerImpl; +import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyArgs; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; +import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs; +import org.apache.hadoop.ozone.om.helpers.OpenKeySession; +import org.apache.hadoop.security.UserGroupInformation; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Benchmark key creation in a bucket in OM. + */ +@State(Scope.Thread) +public class BenchMarkOMKeyAllocation { + + private static final String TMP_DIR = "java.io.tmpdir"; + private String volumeName = UUID.randomUUID().toString(); + private String bucketName = UUID.randomUUID().toString(); + private KeyManager keyManager; + private VolumeManager volumeManager; + private BucketManager bucketManager; + private String path = Paths.get(System.getProperty(TMP_DIR)).resolve( + RandomStringUtils.randomNumeric(6)).toFile() + .getAbsolutePath(); + + @Setup(Level.Trial) + public void setup() throws IOException { + OzoneConfiguration configuration = new OzoneConfiguration(); + configuration.set(OMConfigKeys.OZONE_OM_DB_DIRS, path); + + OmMetadataManagerImpl omMetadataManager = + new OmMetadataManagerImpl(configuration); + volumeManager = new VolumeManagerImpl(omMetadataManager, configuration); + bucketManager = new BucketManagerImpl(omMetadataManager); + + volumeManager.createVolume(new OmVolumeArgs.Builder().setVolume(volumeName) + .setAdminName(UserGroupInformation.getLoginUser().getUserName()) + .setOwnerName(UserGroupInformation.getLoginUser().getUserName()) + .build()); + + bucketManager.createBucket(new OmBucketInfo.Builder() + .setBucketName(bucketName) + .setVolumeName(volumeName).build()); + + keyManager = new KeyManagerImpl(null, omMetadataManager, configuration, + UUID.randomUUID().toString(), null); + } + + @TearDown(Level.Trial) + public void cleanup() throws IOException { + FileUtils.deleteDirectory(new File(path)); + keyManager.stop(); + } + + @Benchmark + public void keyCreation() throws IOException { + OzoneConfiguration configuration = new OzoneConfiguration(); + configuration.set(OMConfigKeys.OZONE_OM_DB_DIRS, path); + + List keyLocationInfos = getKeyInfoList(); + + OmKeyArgs omKeyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName) + .setBucketName(bucketName) + .setKeyName(UUID.randomUUID().toString()) + .setDataSize(0) + .setFactor(HddsProtos.ReplicationFactor.THREE) + .setType(HddsProtos.ReplicationType.RATIS).build(); + OpenKeySession openKeySession = keyManager.openKey(omKeyArgs); + // setting location info list + omKeyArgs.setLocationInfoList(keyLocationInfos); + keyManager.commitKey(omKeyArgs, openKeySession.getId()); + } + + public List getKeyInfoList() { + List omKeyLocationInfoList = new ArrayList<>(); + + omKeyLocationInfoList.add(getKeyInfo()); + omKeyLocationInfoList.add(getKeyInfo()); + + return omKeyLocationInfoList; + } + + public OmKeyLocationInfo getKeyInfo() { + return new OmKeyLocationInfo.Builder().setBlockID( + new BlockID(RandomUtils.nextLong(0, 100000000), + RandomUtils.nextLong(0, 10000000))) + .setLength(RandomUtils.nextLong(0, 10000000)) + .setOffset(0).build(); + } +} diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genesis/Genesis.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genesis/Genesis.java index 3a8efe8e99..d80eee69ad 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genesis/Genesis.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/genesis/Genesis.java @@ -40,6 +40,7 @@ private Genesis() { public static void main(String[] args) throws RunnerException { Options opt = new OptionsBuilder() .include(BenchMarkContainerStateMap.class.getSimpleName()) + .include(BenchMarkOMKeyAllocation.class.getSimpleName()) // .include(BenchMarkMetadataStoreReads.class.getSimpleName()) // .include(BenchMarkMetadataStoreWrites.class.getSimpleName()) // .include(BenchMarkDatanodeDispatcher.class.getSimpleName())