Skip to content

Add performance tests #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 18, 2022
Merged

Add performance tests #152

merged 2 commits into from
May 18, 2022

Conversation

vr009
Copy link

@vr009 vr009 commented Mar 31, 2022

Added benchmarks of large Select and Replace.
Added a new target in Makefile for running benchmark tests.
Added a new step in ci for running benchmark.
Added description to the README for how to run benchmark tests.

Added calls of b.ResetTimer() to all Benchmark tests before the bench loop.
That call clears all counters of allocs, timers etc. in internal counter.
The preparation before bench loop affected perf results.

Fixes #122

@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch 25 times, most recently from 0c7d836 to 6c411b6 Compare April 6, 2022 09:39
@vr009 vr009 marked this pull request as ready for review April 6, 2022 09:43
@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch from 80498a2 to 453e249 Compare April 8, 2022 08:36
@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch 2 times, most recently from 6dc5ba6 to 9da1984 Compare April 28, 2022 17:02
@vr009 vr009 requested a review from ligurio April 28, 2022 17:04
@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch from 9da1984 to 723873e Compare April 29, 2022 14:02
Added calls of b.ResetTimer() to all Benchmark tests before
running bench loop. That call clears all counters of allocs,
timers etc. The preparation before bench loop affected perf results.

Part of #122
@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch from 723873e to a93024a Compare April 29, 2022 14:07
@vr009 vr009 requested a review from ligurio April 29, 2022 14:09
@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch from a93024a to cf95b4b Compare May 4, 2022 09:22
@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch from cf95b4b to 961ff1b Compare May 6, 2022 07:04
@vr009 vr009 requested a review from ligurio May 6, 2022 07:15
@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch from 961ff1b to 86f904d Compare May 6, 2022 08:15
@vr009 vr009 requested a review from ligurio May 6, 2022 08:18
Makefile Outdated
| tee ${BENCH_FILE}
benchstat ${BENCH_FILE}

${BENCH_REFERENCE_REPO}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • BENCH_REFERENCE_REPO - I would rename it to GO_TARANTOOL_URL for clarity
  • if .. then .. fi is bulky, I would replace it with operator for test condition and command itself
  • you do not need to change dir just for making a git clone
  • Cloning the repository into ${BENCH_PATH} for generating benchmark reference file - target just clones a repository, we don't know here what for we do it. I would remove "for generating benchmark reference file"

Please consider my changes:

diff --git a/Makefile b/Makefile
index ca1fb95..40ff068 100644
--- a/Makefile
+++ b/Makefile
@@ -9,8 +9,9 @@ TEST_PATH ?= ${PROJECT_DIR}/...
 BENCH_FILE := ${BENCH_PATH}/bench.txt
 REFERENCE_FILE := ${BENCH_PATH}/reference.txt
 BENCH_FILES := ${REFERENCE_FILE} ${BENCH_FILE}
-BENCH_REFERENCE_REPO := ${BENCH_PATH}/go-tarantool
 BENCH_OPTIONS := -bench=. -run=^Benchmark -benchmem -benchtime=${DURATION} -count=${COUNT}
+GO_TARANTOOL_URL := https://github.com/tarantool/go-tarantool
+GO_TARANTOOL_DIR := ${BENCH_PATH}/go-tarantool
 
 .PHONY: clean
 clean:
@@ -83,11 +84,11 @@ ${BENCH_FILE} bench:
 		| tee ${BENCH_FILE}
 	benchstat ${BENCH_FILE}
 
-${BENCH_REFERENCE_REPO}:
-	@echo "Cloning the repository into ${BENCH_PATH} for generating benchmark reference file"
-	cd ${BENCH_PATH} && if ! [ -e go-tarantool ]; then git clone https://github.com/tarantool/go-tarantool.git; fi
+${GO_TARANTOOL_DIR}:
+	@echo "Cloning the repository into ${GO_TARANTOOL_DIR}"
+	[ ! -e ${GO_TARANTOOL_DIR} ] && git clone ${GO_TARANTOOL_URL} ${GO_TARANTOOL_DIR}
 
-${REFERENCE_FILE}: ${BENCH_REFERENCE_REPO}
+${REFERENCE_FILE}: ${GO_TARANTOOL_DIR}
 	@echo "Running benchmark tests from master for using results in bench-diff target"
 	cd ${BENCH_PATH}/go-tarantool && git pull && go test ${BENCH_PATH}/go-tarantool/... ${BENCH_OPTIONS} 2>&1 \
 		| tee ${REFERENCE_FILE}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thank you for review!

Copy link
Member

@ligurio ligurio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for changes!

LGTM after processing my comment about target for cloning repository.

@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch 2 times, most recently from e0326f5 to ed4d55e Compare May 12, 2022 09:39
@Totktonada
Copy link
Member

I played around the benchmarking toolkit and have some feedback.

Documentation

I would add a sections regarding benchmarking. I mean, let's add a header for the section to easily spot it visually.

I would start from a quickstart (make bench-deps, make bench, make bench-diff) and then would describe options and show examples how to set them.

I would also add some recommendations how to achieve stable results. I briefly written my suggestions below.

Before any judgments, verify whether results are stable on given host and how large the noise. Run make bench-diff without changes and look on the report. Several times.

There are suggestions how to achieve best results:

  • Close all background applications, especially web browser. Look at top (htop, atop, ...) and if something bubbles there, close it.
  • Disable cron daemon.
  • Disable TurboBoost and set fixed frequency.
    • If you're using intel_pstate frequency driver (it is usually default):

      Disable TurboBoost:

      $ echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo

      Set fixed frequency: not sure it is possible.

    • If you're using acpi-cpufreq driver:

      Ensure you actually don't use intel_pstate:

      $ grep -o 'intel_pstate=\w\+' /proc/cmdline
      intel_pstate=disable
      $ cpupower -c all frequency-info | grep driver:
        driver: acpi-cpufreq
        <...>

      Disable TurboBoost:

      $ echo 0 > /sys/devices/system/cpu/cpufreq/boost

      Set fixed frequency:

      $ cpupower -c all frequency-set -g userspace
      $ cpupower -c all frequency-set -f 1.80GHz # adjust for your CPU

Also I would note that benchstat should be in PATH. I need the following command to start using the Makefile:

$ export PATH="/home/${USER}/go/bin:${PATH}"

Usability

I met several problems.

  1. I had received an error, because my current directory contains symlinks.

    $ pwd
    /home/alex/p/t/go-tarantool
    $ make bench
    Running benchmark tests from the current branch
    go test /home/alex/projects/tarantool-meta/go-tarantool/... -bench=. -run=^Benchmark -benchmem -benchtime=3s -count=5 2>&1 \
     | tee /home/alex/projects/tarantool-meta/go-tarantool/bench/bench.txt
    tee: /home/alex/projects/tarantool-meta/go-tarantool/bench/bench.txt: No such file or directory
    pattern /home/alex/projects/tarantool-meta/go-tarantool/...: directory /home/alex/projects/tarantool-meta/go-tarantool is outside module root (/home/alex/p/t/go-tarantool)
    make: *** [Makefile:84: bench] Error 1
    $ cd $(realpath .)
    $ pwd
    /home/alex/projects/tarantool-meta/go-tarantool
    $ make bench # now it works
  2. I had received an error with custom BENCH_PATH with make bench:

    $ make bench BENCH_PATH=bench29
    Running benchmark tests from the current branch
    go test /home/alex/projects/tarantool-meta/go-tarantool/... -bench=. -run=^Benchmark -benchmem -benchtime=3s -count=5 2>&1 \
     | tee bench29/bench.txt
    tee: bench29/bench.txt: No such file or directory
    <...>

    I expect that the directory will be created on demand.

  3. Custom BENCH_PATH with make bench-diff:

    $ make bench-diff BENCH_PATH=bench29
    <...>
    tee: bench29/reference.txt: No such file or directory
    go: warning: "bench29/go-tarantool/..." matched no packages
    no packages to test
    make: *** [Makefile:94: bench29/reference.txt] Error 1

    However the following works:

    $ make bench-diff BENCH_PATH=$(realpath bench29)

Benchmarking results

Before I disbled TurboBoost I received stable degradation for on make bench-diff disregarding reference/HEAD order. I mean that the second result was always worse. It is why I leave the recommendations above and suggest to include something like this into the document.

But when I disabled TurboBoost, I received 1-2% noise, which looks suitable for comparisons. There are rare spikes, so we anyway should run the comparison several times to ensure that results are good. It is okay for the manual tool.

My resolution is that the tooling is suitable for manual comparisons.

Future thoughts

It would be nice to look around unit-test-like benchmarks / microbenchmarks, which would test parts of the connector without actual interation with tarantool. I think they will be more sensitive. I would not make it a separate task, but would experiment around in the scope of some relevant work.

Copy link
Member

@Totktonada Totktonada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes are okay for me in general.

I propose to look on my feedback (summarized above), fix simple problems, leave warnings in CONTRIBUTING.md on hard problems and land it to master. Feel free to proceed without further reviews.

@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch 2 times, most recently from 9a1f104 to 4f77e34 Compare May 18, 2022 08:50
Added benchmarks of large Select and Replace.
Added a new target in Makefile for running benchmark tests.
Added a new space in config.lua for large Select tests.
Added a new target in Makefile for measuring performance
degradation between current changes and master.
Added a new line in gitignore for ignoring artifacts from bench target.

Added a new step for running benchmark tests in ci.

Added description to the CONTRIBUTING.md for how to
run benchmark tests.

Closes #122
@vr009 vr009 force-pushed the vr009/gh-122-add-perf-tests branch from 4f77e34 to 0d2c868 Compare May 18, 2022 09:18
@vr009 vr009 merged commit 976020c into master May 18, 2022
@vr009 vr009 deleted the vr009/gh-122-add-perf-tests branch May 18, 2022 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance tests
4 participants