|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2019-2022 The Polypheny Project |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | + * copy of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +package org.polypheny.simpleclient.cli; |
| 26 | + |
| 27 | +import com.github.rvesse.airline.HelpOption; |
| 28 | +import com.github.rvesse.airline.annotations.Arguments; |
| 29 | +import com.github.rvesse.airline.annotations.Command; |
| 30 | +import com.github.rvesse.airline.annotations.Option; |
| 31 | +import java.sql.SQLException; |
| 32 | +import java.util.List; |
| 33 | +import javax.inject.Inject; |
| 34 | +import lombok.extern.slf4j.Slf4j; |
| 35 | +import org.polypheny.simpleclient.executor.Executor.ExecutorFactory; |
| 36 | +import org.polypheny.simpleclient.executor.PolyphenyDbMongoQlExecutor.PolyphenyDbMongoQlExecutorFactory; |
| 37 | +import org.polypheny.simpleclient.main.DocBenchScenario; |
| 38 | + |
| 39 | + |
| 40 | +@Slf4j |
| 41 | +@Command(name = "docbench", description = "Mode for quick testing of Polypheny-DB using the DocBench benchmark.") |
| 42 | +public class DocBenchCommand implements CliRunnable { |
| 43 | + |
| 44 | + @SuppressWarnings("SpringAutowiredFieldsWarningInspection") |
| 45 | + @Inject |
| 46 | + private HelpOption<DocBenchCommand> help; |
| 47 | + |
| 48 | + @Arguments(description = "Task { schema | data | workload } and multiplier.") |
| 49 | + private List<String> args; |
| 50 | + |
| 51 | + |
| 52 | + @Option(name = { "-pdb", "--polyphenydb" }, title = "IP or Hostname", arity = 1, description = "IP or Hostname of the Polypheny-DB server (default: 127.0.0.1).") |
| 53 | + public static String polyphenyDbHost = "127.0.0.1"; |
| 54 | + |
| 55 | + |
| 56 | + @Option(name = { "--writeCSV" }, arity = 0, description = "Write a CSV file containing execution times for all executed queries (default: false).") |
| 57 | + public boolean writeCsv = false; |
| 58 | + |
| 59 | + |
| 60 | + @Option(name = { "--queryList" }, arity = 0, description = "Dump all queries into a file (default: false).") |
| 61 | + public boolean dumpQueryList = false; |
| 62 | + |
| 63 | + |
| 64 | + @Override |
| 65 | + public int run() throws SQLException { |
| 66 | + if ( args == null || args.size() < 1 ) { |
| 67 | + System.err.println( "Missing task" ); |
| 68 | + System.exit( 1 ); |
| 69 | + } |
| 70 | + |
| 71 | + int multiplier = 1; |
| 72 | + if ( args.size() > 1 ) { |
| 73 | + multiplier = Integer.parseInt( args.get( 1 ) ); |
| 74 | + if ( multiplier < 1 ) { |
| 75 | + System.err.println( "Multiplier needs to be a integer > 0!" ); |
| 76 | + System.exit( 1 ); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + ExecutorFactory executorFactory = new PolyphenyDbMongoQlExecutorFactory( polyphenyDbHost ); |
| 81 | + |
| 82 | + try { |
| 83 | + if ( args.get( 0 ).equalsIgnoreCase( "data" ) ) { |
| 84 | + DocBenchScenario.data( executorFactory, multiplier, true ); |
| 85 | + } else if ( args.get( 0 ).equalsIgnoreCase( "workload" ) ) { |
| 86 | + DocBenchScenario.workload( executorFactory, multiplier, true, writeCsv, dumpQueryList ); |
| 87 | + } else if ( args.get( 0 ).equalsIgnoreCase( "schema" ) ) { |
| 88 | + DocBenchScenario.schema( executorFactory, true ); |
| 89 | + } else if ( args.get( 0 ).equalsIgnoreCase( "warmup" ) ) { |
| 90 | + DocBenchScenario.warmup( executorFactory, multiplier, true, dumpQueryList ); |
| 91 | + } else { |
| 92 | + System.err.println( "Unknown task: " + args.get( 0 ) ); |
| 93 | + } |
| 94 | + } catch ( Throwable t ) { |
| 95 | + log.error( "Exception while executing DocBench!", t ); |
| 96 | + System.exit( 1 ); |
| 97 | + } |
| 98 | + |
| 99 | + try { |
| 100 | + Thread.sleep( 2000 ); |
| 101 | + } catch ( InterruptedException e ) { |
| 102 | + throw new RuntimeException( "Unexpected interrupt", e ); |
| 103 | + } |
| 104 | + |
| 105 | + return 0; |
| 106 | + } |
| 107 | + |
| 108 | +} |
0 commit comments