Exemplo n.º 1
0
def timeit(hosts=None,
           stmt=None,
           warmup=30,
           repeat=None,
           duration=None,
           concurrency=1,
           output_fmt=None,
           fail_if=None,
           sample_mode='reservoir'):
    """Run the given statement a number of times and return the runtime stats

    Args:
        fail-if: An expression that causes cr8 to exit with a failure if it
            evaluates to true.
            The expression can contain formatting expressions for:
                - runtime_stats
                - statement
                - meta
                - concurrency
                - bulk_size
            For example:
                --fail-if "{runtime_stats.mean} > 1.34"
    """
    num_lines = 0
    log = Logger(output_fmt)
    with Runner(hosts, concurrency, sample_mode) as runner:
        try:
            version_info = aio.run(runner.client.get_server_version)
        except Exception:
            result = aio.run(runner.client.execute, 'select version()')
            version_info = {'hash': None, 'number': result['rows'][0][0]}
        for line in as_statements(lines_from_stdin(stmt)):
            runner.warmup(line, warmup)
            timed_stats = runner.run(line,
                                     iterations=repeat,
                                     duration=duration)
            r = Result(version_info=version_info,
                       statement=line,
                       timed_stats=timed_stats,
                       concurrency=concurrency)
            log.result(r)
            if fail_if:
                eval_fail_if(fail_if, r)
        num_lines += 1
    if num_lines == 0:
        raise SystemExit(
            'No SQL statements provided. Use --stmt or provide statements via stdin'
        )
Exemplo n.º 2
0
def _run_spec(version, spec, result_hosts, env, settings, tmpdir):
    crate_dir = get_crate(version)
    settings.setdefault('cluster.name', str(uuid4()))
    results = []
    with Logger() as log, CrateNode(crate_dir=crate_dir, settings=settings, env=env) as n:
        n.start()
        do_run_spec(
            spec=spec,
            benchmark_hosts=n.http_url,
            log=log,
            result_hosts=result_hosts,
            sample_mode='reservoir',
            action='setup'
        )
        jfr_file = jfr_start(n.process.pid, tmpdir)
        log.result = results.append
        do_run_spec(
            spec=spec,
            benchmark_hosts=n.http_url,
            log=log,
            result_hosts=result_hosts,
            sample_mode='reservoir',
            action='queries'
        )
        jfr_stop(n.process.pid)
        do_run_spec(
            spec=spec,
            benchmark_hosts=n.http_url,
            log=log,
            result_hosts=result_hosts,
            sample_mode='reservoir',
            action='teardown'
        )
        return (results, jfr_extract_metrics(jfr_file))
Exemplo n.º 3
0
def timeit(hosts=None,
           stmt=None,
           warmup=30,
           repeat=None,
           duration=None,
           concurrency=1,
           output_fmt=None,
           fail_if=None,
           sample_mode='reservoir'):
    """Run the given statement a number of times and return the runtime stats

    Args:
        fail-if: An expression that causes cr8 to exit with a failure if it
            evaluates to true.
            The expression can contain formatting expressions for:
                - runtime_stats
                - statement
                - meta
                - concurrency
                - bulk_size
            For example:
                --fail-if "{runtime_stats.mean} > 1.34"
    """
    num_lines = 0
    log = Logger(output_fmt)
    with Runner(hosts, concurrency, sample_mode) as runner:
        version_info = aio.run(runner.client.get_server_version)
        for line in as_statements(lines_from_stdin(stmt)):
            runner.warmup(line, warmup)
            timed_stats = runner.run(line, iterations=repeat, duration=duration)
            r = Result(
                version_info=version_info,
                statement=line,
                timed_stats=timed_stats,
                concurrency=concurrency
            )
            log.result(r)
            if fail_if:
                eval_fail_if(fail_if, r)
        num_lines += 1
    if num_lines == 0:
        raise SystemExit(
            'No SQL statements provided. Use --stmt or provide statements via stdin')
def run(version, spec, env, settings):
    crate_dir = get_crate(version)
    settings.setdefault('cluster.name', str(uuid4()))
    with Logger() as log, CrateNode(crate_dir=crate_dir, settings=settings, env=env) as n:
        n.start()
        do_run_spec(
            spec=spec,
            log=log,
            sample_mode='reservoir',
            benchmark_hosts=n.http_url,
            action='setup'
        )
        with connect(n.http_url) as conn:
            optimize_tables(conn.cursor())
        return gather_sizes(n.data_path)
Exemplo n.º 5
0
def run_spec(spec,
             benchmark_hosts,
             result_hosts=None,
             output_fmt=None,
             logfile_info=None,
             logfile_result=None,
             action=None,
             fail_if=None,
             sample_mode='reservoir'):
    """Run a spec file, executing the statements on the benchmark_hosts.

    Short example of a spec file:

        [setup]
        statement_files = ["sql/create_table.sql"]

            [[setup.data_files]]
            target = "t"
            source = "data/t.json"

        [[queries]]
        statement = "select count(*) from t"
        iterations = 2000
        concurrency = 10

        [teardown]
        statements = ["drop table t"]

    See https://github.com/mfussenegger/cr8/tree/master/specs
    for more examples.

    Args:
        spec: path to a spec file
        benchmark_hosts: hostname[:port] pairs of Crate nodes
        result_hosts: optional hostname[:port] Crate node pairs into which the
            runtime statistics should be inserted.
        output_fmt: output format
        action: Optional action to execute.
            Default is to execute all actions - setup, queries and teardown.
            If present only the specified action will be executed.
            The argument can be provided multiple times to execute more than
            one action.
        fail-if: An expression that causes cr8 to exit with a failure if it
            evaluates to true.
            The expression can contain formatting expressions for:
                - runtime_stats
                - statement
                - meta
                - concurrency
                - bulk_size
            For example:
                --fail-if "{runtime_stats.mean} > 1.34"
    """
    with Logger(output_fmt=output_fmt,
                logfile_info=logfile_info,
                logfile_result=logfile_result) as log:
        do_run_spec(spec=spec,
                    benchmark_hosts=benchmark_hosts,
                    log=log,
                    result_hosts=result_hosts,
                    action=action,
                    fail_if=fail_if,
                    sample_mode=sample_mode)