Last active
April 18, 2020 15:33
-
-
Save brfrn169/6a57175d934734b2a2c36652925ffdf6 to your computer and use it in GitHub Desktop.
benchmarking for FSNamesystem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.apache.hadoop; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.fs.FSDataInputStream; | |
import org.apache.hadoop.fs.FSDataOutputStream; | |
import org.apache.hadoop.fs.FileSystem; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.fs.permission.FsPermission; | |
import org.apache.hadoop.hdfs.HdfsConfiguration; | |
import org.apache.hadoop.hdfs.MiniDFSCluster; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Fork; | |
import org.openjdk.jmh.annotations.Measurement; | |
import org.openjdk.jmh.annotations.Mode; | |
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 org.openjdk.jmh.annotations.Warmup; | |
@State(Scope.Benchmark) | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = 5) | |
@Measurement(iterations = 5) | |
@Fork(5) | |
public class FSNamesystemBenchmark { | |
private MiniDFSCluster cluster; | |
private FileSystem fs; | |
@Setup | |
public void setUp() throws Exception { | |
Configuration conf = new HdfsConfiguration(); | |
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build(); | |
fs = cluster.getFileSystem(); | |
} | |
@TearDown | |
public void tearDown() throws Exception { | |
if (fs != null) { | |
fs.close(); | |
fs = null; | |
} | |
if (cluster != null) { | |
cluster.shutdown(); | |
cluster = null; | |
} | |
} | |
@Benchmark | |
public void benchmark() throws Exception { | |
FSDataOutputStream os = fs.create(new Path("/file")); | |
os.close(); | |
FSDataInputStream is = fs.open(new Path("/file")); | |
is.close(); | |
fs.setPermission(new Path("/file"), new FsPermission(644)); | |
fs.setOwner(new Path("/file"), "alice", "group1"); | |
fs.listStatus(new Path("/")); | |
fs.getFileStatus(new Path("/file")); | |
fs.mkdirs(new Path("/dir")); | |
fs.rename(new Path("/file"), new Path("/file2")); | |
fs.delete(new Path("/file2"), false); | |
} | |
public static void main(String[] args) throws Exception { | |
org.openjdk.jmh.Main.main(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment