liuliquan-marshal commented on code in PR #16864: URL: https://github.com/apache/iceberg/pull/16864#discussion_r3486405891
########## core/src/jmh/java/org/apache/iceberg/io/FileIOBenchmark.java: ########## @@ -0,0 +1,373 @@ +/* + * 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.iceberg.io; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.LocalFileSystem; +import org.apache.iceberg.hadoop.HadoopConfigurable; +import org.apache.iceberg.hadoop.HadoopFileIO; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +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.Threads; +import org.openjdk.jmh.annotations.Warmup; + +/** + * A benchmark that evaluates the raw read/write performance of FileIO implementations. + * + * <p>To run this benchmark with HadoopFileIO on local disk (default): + * + * <pre>{@code + * ./gradlew :iceberg-core:jmh -PjmhIncludeRegex=FileIOBenchmark + * }</pre> + * + * <p>To run with OSSFileIO: + * + * <pre>{@code + * ./gradlew :iceberg-core:jmh \ + * -Dbenchmark.fileIOClass=org.apache.iceberg.aliyun.oss.OSSFileIO \ + * -Dbenchmark.base.path=oss://bucket/benchmark-tmp/ \ + * -Doss.endpoint=https://oss-cn-hangzhou.aliyuncs.com \ + * -Dclient.access-key-id=xxx \ + * -Dclient.access-key-secret=xxx \ + * -PjmhIncludeRegex=FileIOBenchmark + * }</pre> + * + * <p>To run with S3FileIO: + * + * <pre>{@code + * ./gradlew :iceberg-core:jmh \ + * -Dbenchmark.fileIOClass=org.apache.iceberg.aws.s3.S3FileIO \ + * -Dbenchmark.base.path=s3://bucket/benchmark-tmp/ \ + * -Ds3.endpoint=https://s3.amazonaws.com \ + * -Ds3.access-key-id=xxx \ + * -Ds3.secret-access-key=xxx \ + * -PjmhIncludeRegex=FileIOBenchmark + * }</pre> + */ +@Fork(1) +@Warmup(iterations = 3) +@Measurement(iterations = 5) +@BenchmarkMode({Mode.AverageTime, Mode.Throughput}) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +public class FileIOBenchmark { + + private static final String PROPERTIES_FILE = "benchmark-fileio.properties"; + + private static final String[] JVM_PROPERTY_PREFIXES = { + "java.", "sun.", "jdk.", "os.", "user.", "file.", "line.", "path.", "awt." + }; + + @Param("org.apache.iceberg.hadoop.HadoopFileIO") + private String fileIOClass; + + @Param({"1", "64", "1024", "16384", "131072"}) + private int fileSizeKB; + + @Param({"4", "64", "256", "1024"}) + private int bufferSizeKB; + + private FileIO fileIO; + private String runDir; + private List<String> createdFiles; + private byte[] writeBuffer; + private byte[] readBuffer; + private String readFilePath; + private AtomicLong writeCounter; + private Random random; + + @Setup(Level.Trial) + public void before() { + // allow system properties to override @Param values (e.g. -Dbenchmark.fileIOClass=...) + String fileIOOverride = System.getProperty("benchmark.fileIOClass"); Review Comment: Thanks for reviewing, addressed this comment in 6e29bf897dc5ba236915593d948a9bafa2ab3af6. PTAL. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
