Skip to content

Commit

Permalink
IGNITE-23944 Sql. Add TPC DS suite (#4873)
Browse files Browse the repository at this point in the history
  • Loading branch information
korlov42 authored Dec 11, 2024
1 parent c63027e commit 364fe77
Show file tree
Hide file tree
Showing 132 changed files with 6,601 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.ignite.InitParameters;
import org.apache.ignite.internal.app.IgniteImpl;
import org.apache.ignite.internal.catalog.commands.CatalogUtils;
import org.apache.ignite.internal.failure.handlers.configuration.StopNodeOrHaltFailureHandlerConfigurationSchema;
import org.apache.ignite.internal.lang.IgniteStringFormatter;
import org.apache.ignite.internal.sql.engine.property.SqlPropertiesHelper;
import org.apache.ignite.internal.testframework.TestIgnitionManager;
Expand Down Expand Up @@ -72,7 +73,7 @@ public class AbstractMultiNodeBenchmark {
protected static Ignite publicIgnite;
protected static IgniteImpl igniteImpl;

@Param({"false", "true"})
@Param({"false"})
private boolean fsync;

@Nullable
Expand Down Expand Up @@ -205,6 +206,11 @@ private void startCluster() throws Exception {
+ " rest.port: {},\n"
+ " raft.fsync = " + fsync() + ",\n"
+ " system.partitionsLogPath = \"" + logPath() + "\",\n"
+ " failureHandler.handler: {\n"
+ " type: \"" + StopNodeOrHaltFailureHandlerConfigurationSchema.TYPE + "\",\n"
+ " tryStop: true,\n"
+ " timeoutMillis: 60000,\n" // 1 minute for graceful shutdown
+ " },\n"
+ "}";

for (int i = 0; i < nodes(); i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* 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.ignite.internal.benchmark;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.ignite.internal.sql.engine.util.TpcTable;
import org.apache.ignite.sql.IgniteSql;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;

/**
* Abstract benchmark class that initializes schema and fills up tables for TPC suite.
*/
@State(Scope.Benchmark)
@SuppressWarnings({"WeakerAccess", "unused"})
public abstract class AbstractTpcBenchmark extends AbstractMultiNodeBenchmark {
private static final String DATASET_READY_MARK_FILE_NAME = "ready.txt";

protected IgniteSql sql;

abstract TpcTable[] tablesToInit();

abstract Path pathToDataset();

/** Initializes a schema and fills tables with data. */
@Setup
public void initSchema() throws Throwable {
try {
sql = publicIgnite.sql();

if (!Files.exists(workDir().resolve(DATASET_READY_MARK_FILE_NAME))) {
Path pathToDataset = pathToDataset();

if (pathToDataset == null) {
throw new IllegalStateException("Path do dataset is not provided. Please read the comment"
+ " in the beginning of " + this.getClass().getSimpleName() + ".class");
}

System.out.println("Going to create schema...");

for (TpcTable table : tablesToInit()) {
System.out.println("Going to create table \"" + table.tableName() + "\"...");
sql.executeScript(table.ddlScript());
System.out.println("Done");

fillTable(table, pathToDataset);
}

Files.createFile(workDir().resolve(DATASET_READY_MARK_FILE_NAME));
}
} catch (Throwable e) {
nodeTearDown();

throw e;
}
}

private void fillTable(TpcTable table, Path pathToDataset) throws Throwable {
System.out.println("Going to fill table \"" + table.tableName() + "\"...");
long start = System.nanoTime();
Iterable<Object[]> dataProvider = () -> {
try {
return table.dataProvider(pathToDataset);
} catch (IOException e) {
throw new RuntimeException(e);
}
};

Semaphore semaphore = new Semaphore(1024); // 1024 was chosen empirically
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>(null);
AtomicInteger inserted = new AtomicInteger();
int expectedCount = 0;
for (Object[] params : dataProvider) {
semaphore.acquire();
sql.executeAsync(null, table.insertPrepareStatement(), params)
.whenComplete((ignored, ex) -> {
semaphore.release();

int val = inserted.incrementAndGet();
if (val % 10_000 == 0) {
System.out.println(val + " rows uploaded to \"" + table.tableName() + "\"");
}

if (ex != null) {
exceptionHolder.compareAndSet(null, ex);
}
});

if (exceptionHolder.get() != null) {
throw exceptionHolder.get();
}

expectedCount++;
}

while (expectedCount != inserted.intValue()) {
if (exceptionHolder.get() != null) {
throw exceptionHolder.get();
}

Thread.sleep(100);
}

System.out.println("Table \"" + table.tableName() + "\" filled in " + Duration.ofNanos(System.nanoTime() - start));
}

@Override
protected void createTable(String tableName) {
// NO-OP
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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.ignite.internal.benchmark;

import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import org.apache.ignite.internal.sql.engine.util.TpcTable;
import org.apache.ignite.internal.sql.engine.util.tpcds.TpcdsHelper;
import org.apache.ignite.internal.sql.engine.util.tpcds.TpcdsTables;
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.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.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
* Benchmark that runs sql queries from TPC-DS suite via embedded client.
*/
@State(Scope.Benchmark)
@Fork(1)
@Threads(1)
@Warmup(iterations = 10, time = 2)
@Measurement(iterations = 20, time = 2)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@SuppressWarnings({"WeakerAccess", "unused"})
public class TpcdsBenchmark extends AbstractTpcBenchmark {
/*
Minimal configuration of this benchmark requires specifying pathToDataset. Dataset is set of CSV
files with name `{$tableName}.dat` per each table and character `|` as separator.
By default, cluster's work directory will be created as a temporary folder. This implies,
that all data generated by benchmark will be cleared automatically. However, this also implies
that cluster will be recreated on EVERY RUN. To initialize cluster once and then reuse it state
override `AbstractMultiNodeBenchmark.workDir()` method. Don't forget to clear that directory afterwards.
*/

@Override
TpcTable[] tablesToInit() {
return TpcdsTables.values();
}

@Override
Path pathToDataset() {
throw new RuntimeException("Provide path to directory containing <table_name>.dat files");
}

@Param("1")
private String queryId;

private String queryString;

/** Initializes a query string. */
@Setup
public void setUp() throws Throwable {
try {
queryString = TpcdsHelper.getQuery(queryId);
} catch (Throwable e) {
nodeTearDown();

throw e;
}
}

/** Benchmark that measures performance of queries from TPC-DS suite. */
@Benchmark
public void run(Blackhole bh) {
try (var rs = sql.execute(null, queryString)) {
while (rs.hasNext()) {
bh.consume(rs.next());
}
}
}

/**
* Benchmark's entry point.
*/
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + TpcdsBenchmark.class.getSimpleName() + ".*")
.build();

new Runner(opt).run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@

package org.apache.ignite.internal.benchmark;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.apache.ignite.internal.sql.engine.util.TpcTable;
import org.apache.ignite.internal.sql.engine.util.tpch.TpchHelper;
import org.apache.ignite.internal.sql.engine.util.tpch.TpchTables;
import org.apache.ignite.sql.IgniteSql;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand Down Expand Up @@ -54,7 +51,7 @@
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@SuppressWarnings({"WeakerAccess", "unused"})
public class TpchBenchmark extends AbstractMultiNodeBenchmark {
public class TpchBenchmark extends AbstractTpcBenchmark {
/*
Minimal configuration of this benchmark requires specifying pathToDataset. Latest known location
of dataset is https://github.com/cmu-db/benchbase/tree/main/data/tpch-sf0.01 for scale factor 0.01
Expand All @@ -63,53 +60,33 @@ public class TpchBenchmark extends AbstractMultiNodeBenchmark {
By default, cluster's work directory will be created as a temporary folder. This implies,
that all data generated by benchmark will be cleared automatically. However, this also implies
that cluster will be recreated on EVERY RUN. Given there are 25 queries and 2 different modes
(fsync on/off), it results in 50 schema initialization and data upload cycles. To initialize
cluster once and then reuse it state override `AbstractMultiNodeBenchmark.workDir()` method.
Don't forget to clear that directory afterwards.
that cluster will be recreated on EVERY RUN. Given there are 25 queries, it results in 25 schema
initialization and data upload cycles. To initialize cluster once and then reuse it state override
`AbstractMultiNodeBenchmark.workDir()` method. Don't forget to clear that directory afterwards.
*/

private static final String DATASET_READY_MARK_FILE_NAME = "ready.txt";

private final Path pathToDataset = null;
@Override
TpcTable[] tablesToInit() {
return TpchTables.values();
}

/** Useful when you need to initialize only subset of tables. */
private final TpchTables[] tablesToInit = TpchTables.values();
@Override
Path pathToDataset() {
throw new RuntimeException("Provide path to directory containing <table_name>.tbl files");
}

@Param({
"1", "2", "3", "4", "5", "6", "7", "8", "8v", "9", "10", "11", "12", "12v",
"13", "14", "14v", "15", "16", "17", "18", "19", "20", "21", "22"
})
private String queryId;

private IgniteSql sql;
private String queryString;

/** Initializes a schema and fills tables with data. */
/** Initializes a query string. */
@Setup
public void setUp() throws Exception {
try {
sql = publicIgnite.sql();

if (!Files.exists(workDir().resolve(DATASET_READY_MARK_FILE_NAME))) {
if (pathToDataset == null) {
throw new IllegalStateException("Path do dataset is not provided. Please read the comment"
+ " in the beginning of TpchBenchmark.class");
}

System.out.println("Going to create schema...");

for (TpchTables table : tablesToInit) {
System.out.println("Going to create table \"" + table.tableName() + "\"...");
sql.executeScript(table.ddlScript());
System.out.println("Done");

fillTable(table);
}

Files.createFile(workDir().resolve(DATASET_READY_MARK_FILE_NAME));
}

queryString = TpchHelper.getQuery(queryId);
} catch (Exception e) {
nodeTearDown();
Expand Down Expand Up @@ -138,30 +115,4 @@ public static void main(String[] args) throws RunnerException {

new Runner(opt).run();
}

private void fillTable(TpchTables table) {
System.out.println("Going to fill table \"" + table.tableName() + "\"...");
long start = System.nanoTime();
int count = 0;
Iterable<Object[]> dataProvider = () -> {
try {
return table.dataProvider(pathToDataset);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
for (Object[] params : dataProvider) {
sql.execute(null, table.insertPrepareStatement(), params);

if (++count % 10_000 == 0) {
System.out.println("Uploaded " + count + " rows");
}
}
System.out.println("Done in " + Duration.ofNanos(System.nanoTime() - start));
}

@Override
protected void createTable(String tableName) {
// NO-OP
}
}
Loading

0 comments on commit 364fe77

Please sign in to comment.