Skip to content

Commit

Permalink
apacheGH-40830: [Java] Adding Spotless to Performance module (apache#…
Browse files Browse the repository at this point in the history
…42057)

### Rationale for this change

Applying Java code style and formatting options to Performance module.

### What changes are included in this PR?

Java code formatting via spotless plugin has been enabled.

### Are these changes tested?

Yes, but doesn't involve test cases, the plugin itself corrects.

### Are there any user-facing changes?

No

* GitHub Issue: apache#40830

Authored-by: Laurent Goujon <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
laurentgo authored Jun 11, 2024
1 parent ab764f4 commit 12e32f5
Show file tree
Hide file tree
Showing 22 changed files with 205 additions and 363 deletions.
2 changes: 2 additions & 0 deletions java/performance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ under the License.
<description>JMH Performance benchmarks for other Arrow libraries.</description>

<properties>
<checkstyle.config.location>dev/checkstyle/checkstyle-spotless.xml</checkstyle.config.location>
<spotless.java.excludes>none</spotless.java.excludes>
<jmh.version>1.37</jmh.version>
<uberjar.name>benchmarks</uberjar.name>
<skip.perf.benchmarks>true</skip.perf.benchmarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.adapter;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.concurrent.TimeUnit;

import org.apache.arrow.adapter.avro.AvroToArrow;
import org.apache.arrow.adapter.avro.AvroToArrowConfig;
import org.apache.arrow.adapter.avro.AvroToArrowConfigBuilder;
Expand Down Expand Up @@ -52,9 +50,7 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
* Benchmarks for avro adapter.
*/
/** Benchmarks for avro adapter. */
@State(Scope.Benchmark)
public class AvroAdapterBenchmarks {

Expand All @@ -65,21 +61,25 @@ public class AvroAdapterBenchmarks {
private Schema schema;
private BinaryDecoder decoder;

/**
* Setup benchmarks.
*/
/** Setup benchmarks. */
@Setup
public void prepare() throws Exception {
BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
config = new AvroToArrowConfigBuilder(allocator).build();

String schemaStr = "{\n" + " \"namespace\": \"org.apache.arrow.avro\",\n" +
" \"type\": \"record\",\n" + " \"name\": \"testBenchmark\",\n" + " \"fields\": [\n" +
" {\"name\": \"f0\", \"type\": \"string\"},\n" +
" {\"name\": \"f1\", \"type\": \"int\"},\n" +
" {\"name\": \"f2\", \"type\": \"long\"},\n" +
" {\"name\": \"f3\", \"type\": \"boolean\"},\n" +
" {\"name\": \"f4\", \"type\": \"float\"}\n" + " ]\n" + "}";
String schemaStr =
"{\n"
+ " \"namespace\": \"org.apache.arrow.avro\",\n"
+ " \"type\": \"record\",\n"
+ " \"name\": \"testBenchmark\",\n"
+ " \"fields\": [\n"
+ " {\"name\": \"f0\", \"type\": \"string\"},\n"
+ " {\"name\": \"f1\", \"type\": \"int\"},\n"
+ " {\"name\": \"f2\", \"type\": \"long\"},\n"
+ " {\"name\": \"f3\", \"type\": \"boolean\"},\n"
+ " {\"name\": \"f4\", \"type\": \"float\"}\n"
+ " ]\n"
+ "}";
schema = new Schema.Parser().parse(schemaStr);

ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand All @@ -96,19 +96,19 @@ public void prepare() throws Exception {
writer.write(record, encoder);
}

decoder = new DecoderFactory().directBinaryDecoder(new ByteArrayInputStream(out.toByteArray()), null);
decoder =
new DecoderFactory().directBinaryDecoder(new ByteArrayInputStream(out.toByteArray()), null);
}

/**
* Tear down benchmarks.
*/
/** Tear down benchmarks. */
@TearDown
public void tearDown() {
config.getAllocator().close();
}

/**
* Test {@link AvroToArrow#avroToArrowIterator(Schema, Decoder, AvroToArrowConfig)}.
*
* @return useless. To avoid DCE by JIT.
*/
@Benchmark
Expand All @@ -117,7 +117,8 @@ public void tearDown() {
public int testAvroToArrow() throws Exception {
decoder.inputStream().reset();
int sum = 0;
try (AvroToArrowVectorIterator iter = AvroToArrow.avroToArrowIterator(schema, decoder, config)) {
try (AvroToArrowVectorIterator iter =
AvroToArrow.avroToArrowIterator(schema, decoder, config)) {
while (iter.hasNext()) {
VectorSchemaRoot root = iter.next();
IntVector intVector = (IntVector) root.getVector("f1");
Expand All @@ -131,10 +132,8 @@ public int testAvroToArrow() throws Exception {
}

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(AvroAdapterBenchmarks.class.getSimpleName())
.forks(1)
.build();
Options opt =
new OptionsBuilder().include(AvroAdapterBenchmarks.class.getSimpleName()).forks(1).build();

new Runner(opt).run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.adapter.jdbc;

import java.sql.Connection;
Expand All @@ -23,7 +22,6 @@
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.concurrent.TimeUnit;

import org.apache.arrow.adapter.jdbc.consumer.BigIntConsumer;
import org.apache.arrow.adapter.jdbc.consumer.BitConsumer;
import org.apache.arrow.adapter.jdbc.consumer.IntConsumer;
Expand All @@ -50,27 +48,23 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
* Benchmarks for Jdbc adapter.
*/
/** Benchmarks for Jdbc adapter. */
public class JdbcAdapterBenchmarks {
// checkstyle:off: MissingJavadocMethod

private static final int VALUE_COUNT = 3000;

private static final String CREATE_STATEMENT =
"CREATE TABLE test_table (f0 INT, f1 LONG, f2 VARCHAR, f3 BOOLEAN);";
"CREATE TABLE test_table (f0 INT, f1 LONG, f2 VARCHAR, f3 BOOLEAN);";
private static final String INSERT_STATEMENT =
"INSERT INTO test_table (f0, f1, f2, f3) VALUES (?, ?, ?, ?);";
"INSERT INTO test_table (f0, f1, f2, f3) VALUES (?, ?, ?, ?);";
private static final String QUERY = "SELECT f0, f1, f2, f3 FROM test_table;";
private static final String DROP_STATEMENT = "DROP TABLE test_table;";

private static final String URL = "jdbc:h2:mem:JdbcAdapterBenchmarks";
private static final String DRIVER = "org.h2.Driver";

/**
* State object for the jdbc e2e benchmark.
*/
/** State object for the jdbc e2e benchmark. */
@State(Scope.Benchmark)
public static class JdbcState {

Expand All @@ -87,7 +81,8 @@ public static class JdbcState {
@Setup(Level.Trial)
public void prepareState() throws Exception {
allocator = new RootAllocator(Integer.MAX_VALUE);
config = new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(1024).build();
config =
new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(1024).build();
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL);

Expand Down Expand Up @@ -129,9 +124,7 @@ public void tearDownState() throws Exception {
}
}

/**
* State object for the consume benchmark.
*/
/** State object for the consume benchmark. */
@State(Scope.Benchmark)
public static class ConsumeState {

Expand Down Expand Up @@ -166,7 +159,8 @@ public static class ConsumeState {
@Setup(Level.Trial)
public void prepare() throws Exception {
allocator = new RootAllocator(Integer.MAX_VALUE);
config = new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(1024).build();
config =
new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(1024).build();

Class.forName(DRIVER);
conn = DriverManager.getConnection(URL);
Expand Down Expand Up @@ -233,9 +227,7 @@ public void tearDown() throws Exception {
}
}

/**
* State object for the jdbc row consume benchmark.
*/
/** State object for the jdbc row consume benchmark. */
@State(Scope.Benchmark)
public static class RowConsumeState {

Expand All @@ -256,7 +248,11 @@ public static class RowConsumeState {
@Setup(Level.Trial)
public void prepareState() throws Exception {
allocator = new RootAllocator(Integer.MAX_VALUE);
config = new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(VALUE_COUNT).build();
config =
new JdbcToArrowConfigBuilder()
.setAllocator(allocator)
.setTargetBatchSize(VALUE_COUNT)
.build();
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL);

Expand Down Expand Up @@ -305,14 +301,16 @@ public void tearDownState() throws Exception {

/**
* Test {@link JdbcToArrow#sqlToArrowVectorIterator(ResultSet, JdbcToArrowConfig)}.
*
* @return useless. To avoid DCE by JIT.
*/
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public int testJdbcToArrow(JdbcState state) throws Exception {
int valueCount = 0;
try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(state.resultSet, state.config)) {
try (ArrowVectorIterator iter =
JdbcToArrow.sqlToArrowVectorIterator(state.resultSet, state.config)) {
while (iter.hasNext()) {
VectorSchemaRoot root = iter.next();
IntVector intVector = (IntVector) root.getFieldVectors().get(0);
Expand Down Expand Up @@ -349,13 +347,10 @@ public void consumeRowsBenchmark(RowConsumeState state) throws Exception {
}

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(JdbcAdapterBenchmarks.class.getSimpleName())
.forks(1)
.build();
Options opt =
new OptionsBuilder().include(JdbcAdapterBenchmarks.class.getSimpleName()).forks(1).build();

new Runner(opt).run();
}
// checkstyle:on: MissingJavadocMethod
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.algorithm.search;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.IntVector;
Expand All @@ -39,17 +37,13 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
* Benchmarks for {@link ParallelSearcher}.
*/
/** Benchmarks for {@link ParallelSearcher}. */
public class ParallelSearcherBenchmarks {
// checkstyle:off: MissingJavadocMethod

private static final int VECTOR_LENGTH = 1024 * 1024;

/**
* State object for the benchmarks.
*/
/** State object for the benchmarks. */
@State(Scope.Benchmark)
public static class SearchState {

Expand Down Expand Up @@ -106,7 +100,8 @@ public void searchBenchmark(SearchState state) throws Exception {
}

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
Options opt =
new OptionsBuilder()
.include(ParallelSearcherBenchmarks.class.getSimpleName())
.forks(1)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.memory;

import java.util.concurrent.TimeUnit;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.rounding.RoundingPolicy;
import org.apache.arrow.memory.rounding.SegmentRoundingPolicy;
import org.openjdk.jmh.annotations.Benchmark;
Expand All @@ -31,14 +28,10 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
* Benchmarks for allocators.
*/
/** Benchmarks for allocators. */
public class AllocatorBenchmarks {

/**
* Benchmark for the default allocator.
*/
/** Benchmark for the default allocator. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
Expand All @@ -59,9 +52,7 @@ public void defaultAllocatorBenchmark() {
}
}

/**
* Benchmark for allocator with segment rounding policy.
*/
/** Benchmark for allocator with segment rounding policy. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
Expand All @@ -71,7 +62,8 @@ public void segmentRoundingPolicyBenchmark() {
final int segmentSize = 1024;

RoundingPolicy policy = new SegmentRoundingPolicy(segmentSize);
try (RootAllocator allocator = new RootAllocator(AllocationListener.NOOP, bufferSize * numBuffers, policy)) {
try (RootAllocator allocator =
new RootAllocator(AllocationListener.NOOP, bufferSize * numBuffers, policy)) {
ArrowBuf[] buffers = new ArrowBuf[numBuffers];

for (int i = 0; i < numBuffers; i++) {
Expand All @@ -85,10 +77,8 @@ public void segmentRoundingPolicyBenchmark() {
}

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(AllocatorBenchmarks.class.getSimpleName())
.forks(1)
.build();
Options opt =
new OptionsBuilder().include(AllocatorBenchmarks.class.getSimpleName()).forks(1).build();

new Runner(opt).run();
}
Expand Down
Loading

0 comments on commit 12e32f5

Please sign in to comment.