Skip to content

Commit

Permalink
workbench: presets, scenarios, proxy & massive cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Jan 17, 2022
1 parent 3761976 commit 54455d0
Show file tree
Hide file tree
Showing 27 changed files with 15,548 additions and 455 deletions.
66 changes: 27 additions & 39 deletions Makefile
@@ -1,6 +1,17 @@
PROJECT_NAME = cardano-node
NUM_PROC = $(nproc --all)

## One of: shey alra mary alzo
ERA ?= alzo

CLUSTER_PROFILE ?= default-${ERA}
ifneq "${CLUSTER_PROFILE}" "default-${ERA}"
$(warning DEPRECATED: CLUSTER_PROFILE is deprecated, please use PROFILE)
endif

PROFILE ?= ${CLUSTER_PROFILE}
ARGS ?=


help: ## Print documentation
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down Expand Up @@ -30,55 +41,32 @@ test-ghcid: ## Run ghcid on test suites
test-ghcid-nix: ## Run ghcid on test suites with Nix
@ghcid --command="stack ghci --test --main-is $(PROJECT_NAME):test:$(PROJECT_NAME)-test --nix -j$(NUM_PROC)"

test-chairmans-cluster:
@scripts/chairmans-cluster/cluster-test.sh

profiles:
@./nix/workbench/wb dump-profiles

profile-names:
@./nix/workbench/wb profile-names
bench-chainsync: PROFILE=chainsync-${ERA}
bench-chainsync: cluster-shell-dev ## Enter Nix shell and start the chainsync benchmark

CLUSTER_PROFILE ?= default-alzo
CLUSTER_ARGS_EXTRA ?=
cluster-profiles: ## List available workbench profiles (for PROFILE=)
@./nix/workbench/wb profile list

cluster-shell:
nix-shell --max-jobs 8 --cores 0 --show-trace --argstr clusterProfile ${CLUSTER_PROFILE} --arg 'autoStartCluster' true
cluster-shell: ## Enter Nix shell and start the workbench cluster
nix-shell --max-jobs 8 --cores 0 --show-trace --argstr clusterProfile ${PROFILE} --arg 'autoStartCluster' true

shell-dev: CLUSTER_ARGS_EXTRA += --arg 'workbenchDevMode' true
cluster-shell: CLUSTER_ARGS_EXTRA += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true
cluster-shell-dev: CLUSTER_ARGS_EXTRA += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true
cluster-shell-trace: CLUSTER_ARGS_EXTRA += --arg 'autoStartCluster' true --argstr 'autoStartClusterArgs' '--trace --trace-workbench'
cluster-shell-dev-trace: CLUSTER_ARGS_EXTRA += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true --argstr 'autoStartClusterArgs' '--trace --trace-workbench'
shell-dev: ARGS += --arg 'workbenchDevMode' true ## Enter Nix shell, dev mode (workbench run from checkout)
cluster-shell: ARGS += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true ## Enter Nix shell, and start workbench cluster
cluster-shell-dev: ARGS += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true ## Enter Nix shell, dev mode, and start workbench cluster
cluster-shell-trace: ARGS += --arg 'autoStartCluster' true --argstr 'autoStartClusterArgs' '--trace --trace-workbench' ## Enter Nix shell, start workbench cluster, with shell tracing
cluster-shell-dev-trace: ARGS += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true --argstr 'autoStartClusterArgs' '--trace --trace-workbench' ## Enter Nix shell, dev mode, start workbench cluster, with shell tracing
shell-dev cluster-shell-dev cluster-shell-trace cluster-shell-dev-trace: shell

shell:
nix-shell --max-jobs 8 --cores 0 --show-trace --argstr clusterProfile ${CLUSTER_PROFILE} ${CLUSTER_ARGS_EXTRA}
shell: ## Enter Nix shell, CI mode (workbench run from Nix store)
nix-shell --max-jobs 8 --cores 0 --show-trace --argstr clusterProfile ${PROFILE} ${ARGS}

cli node:
cabal --ghc-options="+RTS -qn8 -A32M -RTS" build cardano-$@

BENCH_REPEATS ?= 3
BENCH_CONFIG ?= both
BENCH_TAG ?= HEAD
BENCH_XARGS ?=

profile-chainsync:
scripts/mainnet-via-fetcher.sh ${BENCH_XARGS} --node-config-${BENCH_CONFIG} --repeats ${BENCH_REPEATS} --nix --profile time --tag ${BENCH_TAG}

profile-chainsync-fast: BENCH_XARGS=--skip-prefetch
profile-chainsync-fast: profile-chainsync

clean-profile proclean:
rm -f *.html *.prof *.hp *.stats *.eventlog

clean: clean-profile
rm -rf logs/ socket/ cluster.*

full-clean: clean
rm -rf db dist-newstyle .stack-work $(shell find . -name '*~' -or -name '*.swp')
clean:
rm -rf dist-newstyle .stack-work $(shell find . -name '*~' -or -name '*.swp')

cls:
echo -en "\ec"

.PHONY: stylish-haskell cabal-hashes ghcid ghcid-test run-test test-ghci test-ghcid help clean clean-profile proclean cls setup restore
.PHONY: bench-chainsync cabal-hashes clean cli cls cluster-profiles cluster-shell cluster-shell-dev cluster-shell-dev-trace cluster-shell-trace ghci ghcid help node run-test shell shell-dev stylish-haskell test-ghci test-ghcid test-ghcid-nix
15 changes: 10 additions & 5 deletions bench/tx-generator-config-base.json
Expand Up @@ -2,7 +2,7 @@
"LastKnownBlockVersion-Alt": 0,
"LastKnownBlockVersion-Major": 0,
"LastKnownBlockVersion-Minor": 2,
"Protocol": "RealPBFT",
"Protocol": "Cardano",
"RequiresNetworkMagic": "RequiresMagic",

"TurnOnLogging": true,
Expand All @@ -14,13 +14,17 @@
{
"scFormat": "ScJson",
"scKind": "FileSK",
"scName": "logs/generator.json"
"scName": "logs/generator.json",
"scRotation": {
"rpLogLimitBytes": 300000000,
"rpMaxAgeHours": 24,
"rpKeepFilesNum": 20
}
},
{
"scFormat": "ScText",
"scFormat": "ScJson",
"scKind": "StdoutSK",
"scName": "stdout",
"scRotation": null
"scName": "stdout"
}
],
"defaultBackends": [
Expand All @@ -38,6 +42,7 @@
],

"minSeverity": "Debug",
"TracingVerbosity": "MaximalVerbosity",

"TraceBlockFetchClient": true,
"TraceBlockFetchDecisions": false,
Expand Down
104 changes: 27 additions & 77 deletions nix/supervisord-cluster/default.nix
Expand Up @@ -25,7 +25,7 @@ let
backend =
rec
{ ## Generic Nix bits:
topologyForNode =
topologyForNodeSpec =
{ profile, nodeSpec }:
let inherit (nodeSpec) name i; in
workbench.runWorkbench
Expand Down Expand Up @@ -84,6 +84,14 @@ let
ByronGenesisFile = "../genesis/byron/genesis.json";
});

profileOutput =
{ profile }:
pkgs.runCommand "workbench-profile-outputs-${profile.name}-supervisord" {}
''
mkdir $out
cp ${supervisord.mkSupervisorConf profile} $out/supervisor.conf
'';

## Backend-specific Nix bits:
supervisord =
{
Expand All @@ -93,6 +101,7 @@ let
portShiftEkg = 100;
portShiftPrometheus = 200;

## mkSupervisorConf :: Profile -> SupervisorConf
mkSupervisorConf =
profile:
pkgs.callPackage ./supervisor-conf.nix
Expand Down Expand Up @@ -123,6 +132,11 @@ let
profile = workbenchProfiles.profiles."${profileName}"
or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames workbenchProfiles.profiles)}");

profileOut = workbench.profileOutput { inherit profile;
backendProfileOutput =
backend.profileOutput { inherit profile; };
};

inherit (profile.value) era composition monetary;

path = makeBinPath path';
Expand All @@ -133,97 +147,33 @@ let
++ optionals (!workbenchDevMode)
[ workbench.workbench ];

startClusterUsage = ''
Usage:
start-cluster [FLAGS..]
Flags:
--batch-name NAME Override the batch name (default: ${batchName})
--no-generator | --no-gen Don't auto-start the tx-generator
--trace | --debug Trace the start-cluster script
--trace-wb | --trace-workbench Trace the workbench script
--help This help message
'';

start = pkgs.writeScriptBin "start-cluster" ''
set -euo pipefail
batch_name=${batchName}
run_start_flags=()
while test $# -gt 0
do case "$1" in
--batch-name ) batch_name=$2; shift;;
--no-generator | --no-gen ) run_start_flags+=($1);;
--trace | --debug ) set -x;;
--trace-wb | --trace-workbench ) export WORKBENCH_EXTRA_FLAGS=--trace;;
--help ) cat <<EOF
${startClusterUsage}
EOF
exit 1;;
* ) break;; esac; shift; done
workbench-prebuild-executables
export PATH=$PATH:${path}
wb backend assert-is supervisor
wb backend assert-stopped
wb_run_allocate_args=(
--cache-dir "${cacheDir}"
--base-port ${toString basePort}
--stagger-ports
--
--port-shift-ekg 100
--port-shift-prometheus 200
--supervisor-conf "${backend.supervisord.mkSupervisorConf profile}"
)
wb run allocate $batch_name ${profile.name} "''${wb_run_allocate_args[@]}"
current_run_path=$(wb run current-path)
${workbench.initialiseProfileRunDirShellScript profile "$current_run_path"}
wb run start "''${run_start_flags[@]}" $(wb run current-tag)
echo 'workbench: cluster started. Run `stop-cluster` to stop'
wb start \
--batch-name ${batchName} \
--profile-name ${profileName} \
--profile-out ${profileOut} \
--cache-dir ${cacheDir} \
--base-port ${toString basePort} \
''${WORKBENCH_CABAL_MODE:+--cabal} \
"$@" &&
echo 'workbench: cluster started. Run `stop-cluster` to stop' >&2
'';

stop = pkgs.writeScriptBin "stop-cluster" ''
set -euo pipefail
while test $# -gt 0
do case "$1" in
--trace | --debug ) set -x;;
--trace-wb | --trace-workbench ) export WORKBENCH_EXTRA_FLAGS=--trace;;
* ) break;; esac; shift; done
wb run stop $(wb run current-tag)
wb finish "$@"
'';

restart = pkgs.writeScriptBin "restart-cluster" ''
set -euo pipefail
wb_flags=()
wb_run_restart_flags=()
while test $# -gt 0
do case "$1" in
--no-generator | --no-gen ) wb_run_restart_flags+=($1);;
--trace | --debug | --trace-wb | --trace-workbench )
wb_flags+=(--trace);;
--help ) cat <<EOF
${startClusterUsage}
EOF
exit 1;;
* ) break;; esac; shift; done
wb "''${wb_flags[@]}" run restart "''${wb_run_restart_flags[@]}"
echo "workbench: alternate command for this action: wb run restart"
wb run restart "$@" && \
echo "workbench: alternate command for this action: wb run restart" >&2
'';

in
Expand Down
10 changes: 3 additions & 7 deletions nix/supervisord-cluster/supervisor-conf.nix
Expand Up @@ -38,15 +38,11 @@ let
{
"program:generator" = {
directory = "${stateDir}/generator";
command = "${generator-service.startupScript}";
command = "${stateDir}/generator/start.sh";
stdout_logfile = "${stateDir}/generator/stdout";
stderr_logfile = "${stateDir}/generator/stderr";
autostart = false;
};
"program:webserver" = {
command = "${pkgs.python3}/bin/python -m http.server ${toString (basePort - 1)}";
directory = "${stateDir}/shelley/webserver";
};
}
//
extraSupervisorConfig;
Expand All @@ -56,10 +52,10 @@ let
##
## Refer to: http://supervisord.org/configuration.html#program-x-section-settings
##
nodeSvcSupervisorProgram = { nodeSpec, service, startupScript, ... }:
nodeSvcSupervisorProgram = { nodeSpec, service, ... }:
nameValuePair "program:${nodeSpec.value.name}" {
directory = "${service.value.stateDir}";
command = "${startupScript}";
command = "sh start.sh";
stdout_logfile = "${service.value.stateDir}/stdout";
stderr_logfile = "${service.value.stateDir}/stderr";
};
Expand Down

0 comments on commit 54455d0

Please sign in to comment.