Skip to content

Commit

Permalink
Small changes to run benchmarks for lots of transactions (#1726)
Browse files Browse the repository at this point in the history
Fixes #1724

This slightly modifies the micro benchmark to hake a configurable number
of transactions to run for, and shows how to use it to get memory usage
output.
  • Loading branch information
noonio authored Nov 14, 2024
2 parents 3be7b22 + 41fb994 commit 27fc223
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions hydra-node/bench/micro-bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ import Test.QuickCheck (generate)

main :: IO ()
main = do
(utxo, tx) <- prepareTx
-- Use this env var to run benchmarks for more transations:
--
-- > N_TXNS=1 cabal bench micro --benchmark-options '--json output.json +RTS -T'
--
-- You can then find the `peakMbAllocated` field in the resulting json file.
-- (Sorry, criterion makes it very hard to find this with a simple jq
-- command.)
--
nTxns <- fromMaybe 1 . (>>= readMaybe) <$> lookupEnv "N_TXNS"
(utxo, tx) <- prepareTx nTxns
let jsonNewTx = (Aeson.encode . NewTx) tx
toNewTx bs = object ["tag" .= ("NewTx" :: Text), "transaction" .= String (decodeUtf8 bs)]
cborNewTx = (Aeson.encode . toNewTx . serialiseToCBOR) tx
Expand All @@ -35,9 +44,9 @@ main = do
]
]

prepareTx :: IO (UTxO, Tx)
prepareTx =
second List.head <$> generate (genFixedSizeSequenceOfSimplePaymentTransactions 1)
prepareTx :: Int -> IO (UTxO, Tx)
prepareTx n =
second List.head <$> generate (genFixedSizeSequenceOfSimplePaymentTransactions n)

benchApplyTxs :: (UTxO, Tx) -> Either (Tx, ValidationError) UTxO
benchApplyTxs (utxo, tx) = applyTransactions defaultLedger (ChainSlot 1) utxo [tx]
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/hydra-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ benchmark micro
, hydra-tx
, QuickCheck

ghc-options: -threaded -rtsopts
ghc-options: -threaded -rtsopts -with-rtsopts=-N4

test-suite tests
import: project-config
Expand Down

0 comments on commit 27fc223

Please sign in to comment.