Skip to content

Instantly share code, notes, and snippets.

@azat
Created June 7, 2024 13:40
Show Gist options
  • Save azat/7df0643cebb4ca9835d97734b18647b3 to your computer and use it in GitHub Desktop.
Save azat/7df0643cebb4ca9835d97734b18647b3 to your computer and use it in GitHub Desktop.

Revisions

  1. azat created this gist Jun 7, 2024.
    46 changes: 46 additions & 0 deletions lockfree-rename-benchmark.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/usr/bin/env bash

    # Measure overhead of fsync_part_directory for SELECTs from MergeTree/ReplicatedMergeTree (due to rename under lock)
    # Refs: https://github.com/ClickHouse/ClickHouse/pull/64955

    set -e

    bin=$1 && shift
    id=$BASHPID

    $bin client -nm -q "
    create table rmt_without_fsync (key Int) engine=ReplicatedMergeTree('/tables/{database}/rmt_without_fsync', 'r1') order by tuple() settings fsync_part_directory=0;
    create table rmt_with_fsync (key Int) engine=ReplicatedMergeTree('/tables/{database}/rmt_with_fsync', 'r1') order by tuple() settings fsync_part_directory=1;
    create table mt_without_fsync (key Int) engine=MergeTree() order by tuple() settings fsync_part_directory=0;
    create table mt_with_fsync (key Int) engine=MergeTree() order by tuple() settings fsync_part_directory=1;
    "

    for table in rmt_without_fsync rmt_with_fsync mt_without_fsync mt_with_fsync; do
    echo "*** Testing $table"

    sync
    $bin client -q "system stop merges $table"
    $bin client -q "insert into $table select randConstant()%100 from numbers(1e6)" --min_insert_block_size_rows=1 --insert_deduplicate=0 --insert_keeper_max_retries=0 >/dev/null &
    insert_pid=$!

    $bin benchmark --timelimit 10 --delay 0 -q "select count() from $table" --log_comment "lockfree-rename.$id.$table" "$@"

    kill -INT $insert_pid
    wait

    $bin client -q "drop table $table"
    done

    $bin client -q "system flush logs"

    $bin client --format PrettyCompactMonoBlock -q "
    SELECT
    log_comment,
    count() / dateDiff('second', min(event_time), max(event_time)) AS QPS,
    count() AS queries,
    sum(ProfileEvents['PartsLockWaitMicroseconds']) / queries AS lock_wait_avg,
    quantileExact(0.95)(query_duration_ms) duration_q95
    FROM system.query_log
    WHERE (log_comment LIKE 'lockfree-rename.$id.%') AND (type != 'QueryStart')
    GROUP BY 1
    "