Skip to content
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

[ADP-3091] Add memory benchmarks to CI #4043

Merged
merged 7 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .buildkite/bench-memory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p coreutils gnugrep gawk time haskellPackages.hp2pretty buildkite-agent

set -euo pipefail
echo "------------------------ Setup ------------------------------------------"
TMPDIR="${TMPDIR:-/tmp}"
export TMPDIR="/$TMPDIR/bench/memory"
mkdir -p $TMPDIR
echo "TMPDIR: $TMPDIR"

artifact_name=memory
echo "artifact_name: $artifact_name"

export log="$artifact_name.log"
echo "log: $log"

export error_log="$artifact_name.error.log"
echo "error_log: $error_log"

echo "------------------------ Setup done -------------------------------------"

echo "------------------------ Nix call ---------------------------------------"
nix shell \
'.#ci.benchmarks.memory' \
'.#cardano-node' \
'.#cardano-wallet' \
-c "scripts/bench-memory.sh"

echo "------------------------ Nix call done ----------------------------------"

echo "------------------------ Results ----------------------------------------"
mv cardano-wallet.hp $artifact_name.hp
hp2pretty $artifact_name.hp

if [ -n "${BUILDKITE:-}" ]; then
echo "--- Upload"
buildkite-agent artifact upload $artifact_name.svg
buildkite-agent artifact upload $log
buildkite-agent artifact upload $error_log

echo "+++ Heap profile"
printf '\033]1338;url='"artifact://$artifact_name.svg"';alt='"Heap profile"'\a\n'

fi
echo "------------------------ Results done -----------------------------------"

echo "------------------------ Cleanup ----------------------------------------"
rm -rf $TMPDIR
echo "------------------------ Cleanup done -----------------------------------"
8 changes: 8 additions & 0 deletions .buildkite/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ steps:
queue: adrestia-bench
if: 'build.env("step") == null || build.env("step") =~ /bench-latency/'

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

# TODO: ADP-549 Port migrations test to shelley
# - label: 'Database Migrations Test'
# commands:
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ Makefile
## Lean
*.olean
leanpkg.path

## Artifacts
bench-wallet
memory-time.txt
memory.log
memory
memory.svg
bench-restore
restore-time.txt
restore.log
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,10 @@
constituents =
lib.collect lib.isDerivation packages.tests;
};
ci.benchmarks = packages.benchmarks.cardano-wallet // {

ci.benchmarks =
packages.benchmarks.cardano-wallet-benchmarks //
packages.benchmarks.cardano-wallet // {
Comment on lines +447 to +448
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes a little sense from the outside, is it a temporary state of the things?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No idea, how should it be done ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean the fact that we have benchmarks in two different namespaces:
packages.benchmarks.cardano-wallet-benchmarks
packages.benchmarks.cardano-wallet

The questions are:

  • Why to have wallet benchmarks twice?
  • What's the difference between benchmarks.cardano-wallet-benchmars and benchmarks.cardano-wallet ?

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, the nix expression packages.benchmarks.cardano-package-name contains the benchmark components of the cabal package cardano-package-name. In this case, we have two cabal packages: cardano-wallet and cardano-wallet-benchmarks.

Why to have wallet benchmarks twice?
What's the difference between benchmarks.cardano-wallet-benchmarks and benchmarks.cardano-wallet?

I have put the benchmarks in cardano-wallet-benchmarks into a separate packages because they do not have a compile-time dependency on cardano-wallet, only a run-time dependency.

I'm not against putting them in the same cardano-wallet.cabal file, but I felt that putting the run-time benchmarks into a separate package would be better for enforcing the phase separation (compile/run).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, now I see your logic. This is more like a naming issue. I wonder if we can have this distinction "compile/runtime" reflected in the nix derivation names?

all = pkgs.releaseTools.aggregate {
name = "cardano-wallet-benchmarks";
meta.description = "Build all benchmarks";
Expand Down
5 changes: 3 additions & 2 deletions lib/launcher/src/Cardano/Launcher/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Data.Bifunctor
import Data.List
( isPrefixOf )
import Data.Maybe
( maybeToList )
( fromMaybe, maybeToList )
import Data.Text.Class
( FromText (..), TextDecodingError (..), ToText (..) )
import System.Environment
Expand Down Expand Up @@ -95,6 +95,7 @@ data CardanoNodeConfig = CardanoNodeConfig
, nodeVrfKeyFile :: Maybe FilePath
, nodePort :: Maybe NodePort
, nodeLoggingHostname :: Maybe String
, nodeExecutable :: Maybe FilePath
} deriving (Show, Eq)

-- | Spawns a @cardano-node@ process.
Expand Down Expand Up @@ -122,7 +123,7 @@ cardanoNodeProcess cfg socketPath = do
myEnv <- getEnvironment
let env' = ("CARDANO_NODE_LOGGING_HOSTNAME",) <$> nodeLoggingHostname cfg

pure $ (proc "cardano-node" args)
pure $ (proc (fromMaybe "cardano-node" $ nodeExecutable cfg) args)
{ env = Just $ maybeToList env' ++ myEnv
, cwd = Just $ nodeDir cfg
}
Expand Down
62 changes: 38 additions & 24 deletions lib/launcher/src/Cardano/Launcher/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Cardano.Launcher.Wallet
, CardanoWalletConfig (..)
, NetworkConfig (..)

-- * Run
-- * Run
, CardanoWalletConn
, getWalletPort
) where
Expand All @@ -24,6 +24,8 @@ import Cardano.Launcher.Node
( CardanoNodeConn, nodeSocketFile )
import Control.Tracer
( Tracer (..) )
import Data.Maybe
( fromMaybe )
import Data.Text.Class
( FromText (..), ToText (..) )
import Network.Socket
Expand All @@ -34,8 +36,9 @@ import UnliftIO.Process
{-----------------------------------------------------------------------------
Launching a `cardano-wallet` process
------------------------------------------------------------------------------}

-- | Parameters for connecting to the running wallet process.
newtype CardanoWalletConn = CardanoWalletConn { getWalletPort :: PortNumber }
newtype CardanoWalletConn = CardanoWalletConn {getWalletPort :: PortNumber}
deriving (Show, Eq)

instance ToText CardanoWalletConn where
Expand All @@ -46,21 +49,25 @@ instance FromText CardanoWalletConn where

data NetworkConfig
= Mainnet
| Testnet { nodeByronGenesis :: FilePath }
| Testnet {nodeByronGenesis :: FilePath}
deriving (Show, Eq)

-- | A subset of the @cardano-wallet@ CLI parameters,
-- used for starting the process.
data CardanoWalletConfig = CardanoWalletConfig
{ walletPort :: PortNumber
-- ^ Port number for HTTP API. Good default: 8090.
, walletDatabaseDir :: FilePath
-- ^ Path to the wallet database file.
, walletNetwork :: NetworkConfig
-- ^ Network (mainnet or a testnet) that we connect to.
, extraArgs :: [String]
-- ^ Extra arguments to be passed to the process
} deriving (Show, Eq)
{ walletPort :: PortNumber
-- ^ Port number for HTTP API. Good default: 8090.
, walletDatabaseDir :: FilePath
-- ^ Path to the wallet database file.
, walletNetwork :: NetworkConfig
-- ^ Network (mainnet or a testnet) that we connect to.
, extraArgs :: [String]
-- ^ Extra arguments to be passed to the process
, executable :: Maybe FilePath
-- ^ Path to the @cardano-wallet@ executable.
, workingDir :: Maybe FilePath
}
deriving (Show, Eq)

-- | Spawns a @cardano-wallet@ process.
--
Expand All @@ -74,18 +81,25 @@ withCardanoWallet
-- ^ Callback function with a socket filename and genesis params
-> IO (Either ProcessHasExited a)
withCardanoWallet tr node cfg@CardanoWalletConfig{..} action =
withBackendCreateProcess tr (cardanoWallet cfg node) $
\_ _ -> action $ CardanoWalletConn walletPort
withBackendCreateProcess tr (cardanoWallet cfg node)
$ \_ _ -> action $ CardanoWalletConn walletPort

cardanoWallet :: CardanoWalletConfig -> CardanoNodeConn -> CreateProcess
cardanoWallet CardanoWalletConfig{..} node =
proc "cardano-wallet" $
[ "serve"
, "--node-socket", nodeSocketFile node
, "--database", walletDatabaseDir
, "--port", show walletPort
]
<> case walletNetwork of
Mainnet -> ["--mainnet"]
Testnet path -> ["--testnet", path]
<> extraArgs

let cp = proc (fromMaybe "cardano-wallet" executable)
$ [ "serve"
, "--node-socket"
, nodeSocketFile node
, "--database"
, walletDatabaseDir
, "--port"
, show walletPort
]
<> case walletNetwork of
Mainnet -> ["--mainnet"]
Testnet path -> ["--testnet", path]
<> extraArgs
in cp
{ cwd = workingDir
}
paolino marked this conversation as resolved.
Show resolved Hide resolved
Loading