-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tpc benchmarks as tests (#8125)
- Loading branch information
Showing
7 changed files
with
497 additions
and
21 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import argparse | ||
import subprocess | ||
import pathlib | ||
import os | ||
from sys import stderr | ||
|
||
|
||
def variant(string): | ||
if string not in ["h", "ds"]: | ||
raise ValueError("variant must be h or ds") | ||
return string | ||
|
||
|
||
def paths(string): | ||
return list(map(pathlib.Path, string.split(";"))) | ||
|
||
|
||
def parse_args(): | ||
subparser = argparse.ArgumentParser() | ||
|
||
subparser.add_argument('--is-test', action="store_true", default=False) | ||
|
||
subparser.add_argument('--datasize', type=int, default=1) | ||
subparser.add_argument('--variant', type=variant, default='h') | ||
subparser.add_argument('--tasks', type=int, default=1) | ||
|
||
subparser.add_argument('-o', '--output', default="./results") | ||
subparser.add_argument('--clean-old', action="store_true", default=False) | ||
subparser.add_argument('--query-filter', action="append", default=[]) | ||
|
||
args, argv = subparser.parse_known_args() | ||
|
||
if args.is_test: | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('--dqrun', type=pathlib.Path) | ||
parser.add_argument('--gen-queries', type=pathlib.Path) | ||
parser.add_argument('--downloaders-dir', type=pathlib.Path) | ||
parser.add_argument('--udfs-dir', type=paths) | ||
parser.add_argument('--fs-cfg', type=pathlib.Path) | ||
parser.add_argument('--flame-graph', type=pathlib.Path) | ||
parser.add_argument('--result-compare', type=pathlib.Path) | ||
parser.add_argument('--gateways-cfg', type=pathlib.Path) | ||
parser.add_argument('--runner-path', type=pathlib.Path) | ||
|
||
return parser.parse_args(argv, namespace=args) | ||
else: | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('--ydb-root', type=lambda path: pathlib.Path(path).resolve(), default="../../../../") | ||
|
||
args = parser.parse_args(argv, namespace=args) | ||
|
||
args.dqrun = args.ydb_root / "ydb" / "library" / "yql" / "tools" / "dqrun" / "dqrun" | ||
args.gen_queries = args.ydb_root / "ydb" / "library" / "benchmarks" / "gen_queries" / "gen_queries" | ||
args.downloaders_dir = args.ydb_root / "ydb" / "library" / "benchmarks" / "runner" | ||
args.fs_cfg = args.ydb_root / "ydb" / "library" / "yql" / "tools" / "dqrun" / "examples" / "fs.conf" | ||
args.flame_graph = args.ydb_root / "contrib" / "tools" / "flame-graph" | ||
args.result_compare = args.ydb_root / "ydb" / "library" / "benchmarks" / "runner" / "result_compare" / "result_compare" | ||
args.gateways_cfg = args.ydb_root / "ydb" / "library" / "benchmarks" / "runner" / "runner" / "test-gateways.conf" | ||
args.runner_path = args.ydb_root / "ydb" / "library" / "benchmarks" / "runner" / "runner" / "runner" | ||
|
||
udfs_prefix = args.ydb_root / "ydb" / "library" / "yql" / "udfs" / "common" | ||
args.udfs_dir = [udfs_prefix / name for name in ["set", "url_base", "datetime2", "re2", "math", "unicode_base"]] | ||
|
||
return args | ||
|
||
|
||
class Runner: | ||
def prepare_queries_dir(self, custom_pragmas): | ||
print("Preparing queries...", file=stderr) | ||
self.queries_dir.mkdir(parents=True, exist_ok=True) | ||
cmd = [str(self.args.gen_queries)] | ||
cmd += ["--output", f"{self.queries_dir}"] | ||
cmd += ["--variant", f"{self.args.variant}"] | ||
cmd += ["--syntax", "yql"] | ||
cmd += ["--dataset-size", f"{self.args.datasize}"] | ||
for it in custom_pragmas: | ||
cmd += ["--pragma", it] | ||
res = subprocess.run(cmd) | ||
if res.returncode != 0: | ||
raise OSError("Failed to prepare queries") | ||
|
||
def prepare_tpc_dir(self): | ||
print("Preparing tpc...", file=stderr) | ||
cmd = [f"./download_files_{self.args.variant}_{self.args.datasize}.sh"] | ||
res = subprocess.run(cmd, cwd=self.args.downloaders_dir) | ||
if res.returncode != 0: | ||
raise OSError("Failed to prepare tpc") | ||
|
||
def __init__(self, args, enable_spilling): | ||
self.args = args | ||
self.enable_spilling = enable_spilling | ||
|
||
self.queries_dir = pathlib.Path(f"queries{"+" if self.enable_spilling else "-"}spilling-{args.datasize}-{args.tasks}") | ||
if self.args.clean_old or not self.queries_dir.exists(): | ||
self.prepare_queries_dir([ | ||
f"dq.MaxTasksPerStage={self.args.tasks}", | ||
"dq.OptLLVM=ON" | ||
] + [ | ||
"dq.UseFinalizeByKey=true", | ||
"dq.EnableSpillingNodes=All", | ||
] if self.enable_spilling else []) | ||
self.tpc_dir = pathlib.Path(f"{self.args.downloaders_dir}/tpc/{self.args.variant}/{self.args.datasize}") | ||
if self.args.clean_old or not self.tpc_dir.exists(): | ||
self.prepare_tpc_dir() | ||
if not pathlib.Path("./tpc").exists(): | ||
os.symlink(f"{self.args.downloaders_dir}/tpc", f"{pathlib.Path("./tpc")}", target_is_directory=True) | ||
|
||
self.result_dir = pathlib.Path(f"{self.args.output}/{"with" if self.enable_spilling else "no"}-spilling/{args.variant}-{args.datasize}-{args.tasks}").resolve() | ||
self.result_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
def run(self): | ||
cmd = ["/usr/bin/time", f"{str(self.args.runner_path)}"] | ||
# cmd += ["--perf"] | ||
for it in self.args.query_filter: | ||
cmd += ["--include-q", it] | ||
cmd += ["--query-dir", f"{str(self.queries_dir)}/{self.args.variant}"] | ||
cmd += ["--bindings", f"{str(self.queries_dir)}/{self.args.variant}/bindings.json"] | ||
cmd += ["--result-dir", str(self.result_dir)] | ||
cmd += ["--flame-graph", str(self.args.flame_graph)] | ||
cmd += [f"{self.args.dqrun}", "-s"] | ||
cmd += ["--enable-spilling"] if self.enable_spilling else [] | ||
cmd += ["--udfs-dir", ";".join(map(str, self.args.udfs_dir))] | ||
cmd += ["--fs-cfg", f"{str(self.args.fs_cfg)}"] | ||
cmd += ["--gateways-cfg", f"{str(self.args.gateways_cfg)}"] | ||
print("Running runner...", file=stderr) | ||
subprocess.run(cmd) | ||
|
||
print("Run results at: ", self.result_dir) | ||
return self.result_dir | ||
|
||
|
||
def result_compare(args, to_compare): | ||
print("Comparing...") | ||
cmd = [f"{args.result_compare}"] | ||
cmd += ["-v"] | ||
cmd += to_compare | ||
with open(f"{args.output}/result-{args.variant}-{args.datasize}-{args.tasks}.htm", "w") as result_table: | ||
res = subprocess.run(cmd, stdout=result_table) | ||
if res.returncode != 0: | ||
raise OSError("Failed to compare result") | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
|
||
results = [] | ||
print("With spilling...", file=stderr) | ||
results.append(Runner(args, True).run()) | ||
print("No spilling...", file=stderr) | ||
results.append(Runner(args, False).run()) | ||
|
||
if not args.is_test: | ||
result_compare(args, results) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
PY3_PROGRAM() | ||
|
||
PY_SRCS( | ||
MAIN run_tests.py | ||
) | ||
|
||
PEERDIR( | ||
) | ||
|
||
END() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,4 @@ PY_SRCS( | |
MAIN runner.py | ||
) | ||
|
||
PEERDIR( | ||
) | ||
|
||
END() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import yatest.common | ||
import pathlib | ||
import sys | ||
import os | ||
|
||
|
||
class Runner: | ||
DEPS = { | ||
"run_tests" : "ydb/library/benchmarks/runner/run_tests", | ||
"dqrun" : "ydb/library/yql/tools/dqrun", | ||
"gen-queries" : "ydb/library/benchmarks/gen_queries", | ||
"result-compare" : "ydb/library/benchmarks/runner/result_compare", | ||
"runner" : "ydb/library/benchmarks/runner/runner" | ||
} | ||
|
||
DATA = { | ||
"fs-cfg" : "ydb/library/yql/tools/dqrun/examples/fs.conf", | ||
"gateways-cfg" : "ydb/library/benchmarks/runner/runner/test-gateways.conf", | ||
"flame-graph" : "contrib/tools/flame-graph", | ||
"downloaders-dir" : "ydb/library/benchmarks/runner", | ||
} | ||
|
||
UDFS = [ | ||
"ydb/library/yql/udfs/common/set", | ||
"ydb/library/yql/udfs/common/url_base", | ||
"ydb/library/yql/udfs/common/datetime2", | ||
"ydb/library/yql/udfs/common/re2" | ||
] | ||
|
||
def __init__(self): | ||
self.deps = {name : pathlib.Path(yatest.common.binary_path(path)) for name, path in self.DEPS.items()} | ||
self.udfs = [pathlib.Path(yatest.common.binary_path(path)) for path in self.UDFS] | ||
self.data = {name : pathlib.Path(yatest.common.source_path(path)) for name, path in self.DATA.items() if name} | ||
self.output = pathlib.Path(yatest.common.output_path()) | ||
self.results_path = self.output / "results" | ||
self.results_path.mkdir() | ||
|
||
self.cmd = [str(self.deps["run_tests"]) + "/run_tests", "--is-test"] | ||
self.cmd += ["--dqrun", str(self.deps["dqrun"]) + "/dqrun"] | ||
self.cmd += ["--gen-queries", str(self.deps["gen-queries"]) + "/gen_queries"] | ||
self.cmd += ["--result-compare", str(self.deps["result-compare"]) + "/result_compare"] | ||
self.cmd += ["--downloaders-dir", str(self.data["downloaders-dir"])] | ||
self.cmd += ["--runner", str(self.deps["runner"]) + "/runner"] | ||
self.cmd += ["--flame-graph", str(self.data["flame-graph"])] | ||
self.cmd += ["--udfs-dir", ";".join(map(str, self.udfs))] | ||
self.cmd += ["--fs-cfg", str(self.data["fs-cfg"])] | ||
self.cmd += ["--gateways-cfg", str(self.data["gateways-cfg"])] | ||
self.cmd += ["-o", str(self.results_path)] | ||
|
||
def wrapped_run(self, variant, datasize, tasks, query_filter): | ||
cmd = self.cmd | ||
cmd += ["--variant", f"{variant}"] | ||
cmd += ["--datasize", f"{datasize}"] | ||
cmd += ["--tasks", f"{tasks}"] | ||
cmd += ["--clean-old"] | ||
if query_filter: | ||
cmd += ["--query-filter", f"{query_filter}"] | ||
yatest.common.execute(cmd, stdout=sys.stdout, stderr=sys.stderr) | ||
|
||
|
||
def upload(result_path, s3_folder): | ||
uploader = pathlib.Path(yatest.common.source_path("ydb/library/benchmarks/runner/upload_results.py")).resolve() | ||
cmd = ["python3", str(uploader)] | ||
cmd += ["--result-path", str(result_path)] | ||
cmd += ["--s3-folder", str(s3_folder)] | ||
yatest.common.execute(cmd, stdout=sys.stdout, stderr=sys.stderr) | ||
|
||
|
||
def test_tpc(): | ||
is_ci = os.environ.get("PUBLIC_DIR") is not None | ||
|
||
runner = Runner() | ||
runner.wrapped_run("h", 1, 1, None) | ||
result_path = runner.results_path.resolve() | ||
print("Results path: ", result_path, file=sys.stderr) | ||
|
||
if is_ci: | ||
s3_folder = pathlib.Path(os.environ["PUBLIC_DIR"]).resolve() | ||
|
||
upload(result_path, s3_folder) |
Oops, something went wrong.