Skip to content

Commit

Permalink
Merge #3779
Browse files Browse the repository at this point in the history
3779: [ADP-2811] Create `api` benchmark r=HeinrichApfelmus a=HeinrichApfelmus

### Overview

This pull request adds a benchmark `api` and includes it in the `nightly` queue.

The idea of this benchmark is to load wallet states from a directory of database file and measure the running times of various API calls. These wallets are not synchronized to the chain.

Here, "API" refers to the exports of `Cardano.Wallet`, which often mirror the HTTP endpoints, but do not coincide with it. The `restore` benchmark uses a similar approach.

### Comments

* Eventually, we may want to remove the timing measurements of the API calls from the `restore` benchmark, and replicate them in this benchmark instead. 🤔 The advantage of the `api` benchmark is that it has a much faster turnaround time and can be used for wallet UTxO distributions that look different from those generated by the `restore` benchmark ones.  n this way, it can be used to debug performance issues.

### Issue number

ADP-2811

Co-authored-by: Heinrich Apfelmus <heinrich.apfelmus@iohk.io>
  • Loading branch information
iohk-bors[bot] and HeinrichApfelmus committed Apr 1, 2023
2 parents 80fec43 + 442af9b commit 6c853c6
Show file tree
Hide file tree
Showing 15 changed files with 952 additions and 27 deletions.
65 changes: 65 additions & 0 deletions .buildkite/bench-api.sh
@@ -0,0 +1,65 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p nix coreutils gnugrep gawk buildkite-agent

set -euo pipefail

# C.UTF-8 = UTF-8 based locale that is not associated with a natural language.
# This seems necessary so that programs compiled with GHC don't choke,
# see also <https://stackoverflow.com/a/63751678>.
export LANG=C.UTF-8

if [ -n "${SCRATCH_DIR:-}" ]; then
mkdir -pv "$SCRATCH_DIR"
export TMPDIR="$SCRATCH_DIR/tmp"
mkdir -pv "$TMPDIR"
fi

bench=api
log=api.log
results=api.txt
total_time=api-time.txt

echo "--- Build"

nix build .#ci.benchmarks.api -o bench-api
bench="./bench-api/bin/api lib/wallet/test/data/api-bench"

echo "--- Run benchmark"

$bench +RTS -N2 -qg -A1m -I0 -T -M16G -RTS 2>&1 | tee $log
# Reminder on GHC RTS options:
# -N ⟨x⟩
# Use ⟨x⟩ simultaneous threads when running the program.
# -qg ⟨gen⟩
# Use parallel GC in generation ⟨gen⟩ and higher.
# Omitting ⟨gen⟩ turns off the parallel GC completely,
# reverting to sequential GC.
# -A allocation area size used by the garbage collector
# -I0 disables the idle GC.
# -T produce runtime-system statistics, such as
# the amount of time spent executing the program
# and in the garbage collector.
# -T collects the data, but produces no output.
# -M ⟨size⟩
# Set the maximum heap size to ⟨size⟩ bytes.
# -h Generates a basic heap profile, in the file prog.hp.

echo "--- Results"

grep -v INFO $log | awk '/All results/,EOF { print $0 }' >$results
cat $results

if [ -n "${BUILDKITE:-}" ]; then
echo "--- Upload"
buildkite-agent artifact upload $results

for file in *.json; do
buildkite-agent artifact upload $file
done
fi

if [ -z "$(cat $results)" ]; then
echo "+++ Bad news"
echo "FAILED - Missing results" >/dev/stderr
exit 1
fi
8 changes: 8 additions & 0 deletions .buildkite/nightly.yml
Expand Up @@ -36,6 +36,14 @@ steps:
queue: benchmark
if: 'build.env("step") == null || build.env("step") =~ /restore-mainnet/'

- label: 'API benchmark'
command: "./.buildkite/bench-api.sh"
timeout_in_minutes: 210
agents:
system: x86_64-linux
queue: benchmark
if: 'build.env("step") == null || build.env("step") =~ /bench-api/'

- label: 'Database benchmark'
command: "./.buildkite/bench-db.sh"
timeout_in_minutes: 210
Expand Down
18 changes: 18 additions & 0 deletions .buildkite/pipeline.yml
Expand Up @@ -127,6 +127,24 @@ steps:
env:
TMPDIR: "/cache"

- block: 'Run benchmark (api)'
depends_on: linux-nix
key: trigger-benchmark-api

- label: 'Run benchmark (api)'
command: "./.buildkite/bench-api.sh"
depends_on: trigger-benchmark-api
timeout_in_minutes: 20
agents:
system: x86_64-linux
# We do not use the benchmark queue here, as we don't want
# to use system resources that are intended for long-running processes
# to perform quick-and-dirty benchmark runs.
# queue: benchmark
if: 'build.env("step") == null || build.env("step") =~ /bench-api/'
env:
TMPDIR: "/cache"

- label: 'Check nix (macOS)'
key: macos-nix
depends_on: linux-nix
Expand Down
1 change: 1 addition & 0 deletions lib/balance-tx/cardano-balance-tx.cabal
Expand Up @@ -43,6 +43,7 @@ library
, cardano-wallet-primitive
, cardano-wallet-test-utils
, containers
, deepseq
, fmt
, generic-lens
, generics-sop
Expand Down
Expand Up @@ -117,6 +117,8 @@ import Cardano.Wallet.Primitive.Types.UTxOSelection
( UTxOSelection )
import Control.Arrow
( (&&&) )
import Control.DeepSeq
( NFData )
import Control.Monad.Random.Class
( MonadRandom (..) )
import Control.Monad.Trans.Except
Expand Down Expand Up @@ -414,6 +416,8 @@ data SelectionOf change = Selection
}
deriving (Generic, Eq, Show)

instance NFData change => NFData (SelectionOf change)

-- | The default type of selection.
--
-- In this type of selection, change values do not have addresses assigned.
Expand Down

0 comments on commit 6c853c6

Please sign in to comment.