Skip to content

Commit

Permalink
wip: Move restore benchmarks to shelley package
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jul 27, 2020
1 parent 665431b commit 10e76e6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 91 deletions.
17 changes: 4 additions & 13 deletions .buildkite/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,24 @@ env:
SCRATCH_DIR: "/scratch/cardano-wallet"

steps:
- label: 'Restore benchmark - mainnet'
command: "./.buildkite/bench-restore.sh byron mainnet"
- label: 'Restore benchmark - cardano mainnet'
command: "./.buildkite/bench-restore.sh shelley mainnet"
env:
HOME: "/cache/cardano-wallet.home"
timeout_in_minutes: 600
agents:
system: x86_64-linux
queue: benchmark

- label: 'Restore benchmark - testnet'
command: "./.buildkite/bench-restore.sh byron testnet"
- label: 'Restore benchmark - cardano testnet'
command: "./.buildkite/bench-restore.sh shelley testnet"
env:
HOME: "/cache/cardano-wallet.home"
timeout_in_minutes: 600
agents:
system: x86_64-linux
queue: benchmark

- label: 'Restore benchmark - shelley_testnet'
command: "./.buildkite/bench-restore.sh shelley shelley_testnet"
env:
HOME: "/cache/cardano-wallet.home"
timeout_in_minutes: 60
agents:
system: x86_64-linux
queue: benchmark

- label: 'Database benchmark'
command: "./.buildkite/bench-db.sh"
timeout_in_minutes: 120
Expand Down
49 changes: 0 additions & 49 deletions lib/byron/cardano-wallet-byron.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -200,55 +200,6 @@ test-suite integration
Test.Integration.Byron.Scenario.API.Migrations
Test.Integration.Byron.Scenario.CLI.Transactions

benchmark restore
default-language:
Haskell2010
default-extensions:
NoImplicitPrelude
OverloadedStrings
ghc-options:
-threaded -rtsopts
-Wall
if (flag(release))
ghc-options: -O2 -Werror
build-depends:
base
, bytestring
, cardano-addresses
, cardano-wallet-core
, cardano-wallet-core-integration
, optparse-applicative
, cardano-wallet-byron
, cardano-wallet-launcher
, ouroboros-network
, contra-tracer
, containers
, criterion-measurement
, cryptonite
, deepseq
, digest
, directory
, filepath
, fmt
, iohk-monitoring
, persistent
, persistent-template
, process
, say
, temporary
, text
, time
, transformers
type:
exitcode-stdio-1.0
hs-source-dirs:
bench
main-is:
Restore.hs
other-modules:
Cardano.Wallet.Primitive.AddressDiscovery.Any
Cardano.Wallet.Primitive.AddressDiscovery.Any.TH

benchmark latency
default-language:
Haskell2010
Expand Down
59 changes: 30 additions & 29 deletions lib/byron/bench/Restore.hs → lib/shelley/bench/Restore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
-- Easiest run using
-- @
-- $ export NODE_DB="node-db-testnet"
-- $ nix-build -A benchmarks.cardano-wallet-byron.restore -o restore && ./restore/bin/restore testnet
-- $ nix-build -A benchmarks.cardano-wallet-shelley.restore -o restore && ./restore/bin/restore testnet
-- @
--
-- or
-- @
-- $ ./.buildkite/bench-restore.sh byron testnet
-- $ ./.buildkite/bench-restore.sh shelley testnet
-- @
--
-- since it relies on lots of configuration most most easily retrieved with nix.
Expand All @@ -44,23 +44,23 @@ import Cardano.Wallet.BenchShared
, execBenchWithNode
, runBenchmarks
)
import Cardano.Wallet.Byron
( SomeNetworkDiscriminant (..) )
import Cardano.Wallet.Byron.Compatibility
( Byron
import Cardano.Wallet.Shelley
( SomeNetworkDiscriminant (..), HasNetworkId(..) )
import Cardano.Wallet.Shelley.Compatibility
( Shelley
, NodeVersionData
, emptyGenesis
, fromByronBlock
, fromCardanoBlock
, fromNetworkMagic
, mainnetVersionData
)
import Cardano.Wallet.Byron.Launch
import Cardano.Wallet.Shelley.Launch
( NetworkConfiguration (..), parseGenesisData )
import Cardano.Wallet.Byron.Network
import Cardano.Wallet.Shelley.Network
( withNetworkLayer )
import Cardano.Wallet.Byron.Transaction
import Cardano.Wallet.Shelley.Transaction
( newTransactionLayer )
import Cardano.Wallet.Byron.Transaction.Size
import Cardano.Wallet.Shelley.Transaction.Size
( MaxSizeOf (..) )
import Cardano.Wallet.DB
( DBLayer )
Expand All @@ -79,8 +79,8 @@ import Cardano.Wallet.Primitive.AddressDerivation
, digest
, publicKey
)
import Cardano.Wallet.Primitive.AddressDerivation.Byron
( ByronKey )
import Cardano.Wallet.Primitive.AddressDerivation.Shelley
( ShelleyKey )
import Cardano.Wallet.Primitive.AddressDerivation.Icarus
( IcarusKey )
import Cardano.Wallet.Primitive.AddressDiscovery
Expand Down Expand Up @@ -152,29 +152,29 @@ import System.IO.Temp

import qualified Cardano.Wallet as W
import qualified Cardano.Wallet.DB.Sqlite as Sqlite
import qualified Cardano.Wallet.Primitive.AddressDerivation.Byron as Byron
import qualified Cardano.Wallet.Primitive.AddressDerivation.Shelley as Shelley
import qualified Data.ByteString.Char8 as B8
import qualified Data.List.NonEmpty as NE
import qualified Data.Text as T
import qualified Data.Text.Encoding as T

main :: IO ()
main = execBenchWithNode argsNetworkConfig byronRestoreBench
main = execBenchWithNode argsNetworkConfig cardanoRestoreBench

{-------------------------------------------------------------------------------
Byron benchmarks
Shelley benchmarks
-------------------------------------------------------------------------------}

argsNetworkConfig :: RestoreBenchArgs -> NetworkConfiguration
argsNetworkConfig args = case argNetworkName args of
"mainnet" ->
MainnetConfig (SomeNetworkDiscriminant $ Proxy @'Mainnet, mainnetVersionData)
_ ->
TestnetConfig (argsNetworkDir args </> "genesis.json")
TestnetConfig (argsNetworkDir args </> "byron-genesis.json")

-- | Run all available benchmarks.
byronRestoreBench :: Trace IO Text -> NetworkConfiguration -> FilePath -> IO ()
byronRestoreBench tr c socketFile = do
cardanoRestoreBench :: Trace IO Text -> NetworkConfiguration -> FilePath -> IO ()
cardanoRestoreBench tr c socketFile = do
(SomeNetworkDiscriminant networkProxy, np, vData, _b)
<- unsafeRunExceptT $ parseGenesisData c

Expand All @@ -195,15 +195,15 @@ byronRestoreBench tr c socketFile = do

-- Temporary directory for storing socket
tmpDir <- getCanonicalTemporaryDirectory
>>= \tmpRoot -> createTempDirectory tmpRoot "cw-byron"
>>= \tmpRoot -> createTempDirectory tmpRoot "cw-shelley"

let network = networkDescription networkProxy
sayErr $ "Network: " <> network

prepareNode networkProxy socketFile np vData
runBenchmarks
[ bench ("restore " <> network <> " seq")
(bench_restoration @_ @ByronKey
(bench_restoration @_ @ShelleyKey
networkProxy
tr
socketFile
Expand Down Expand Up @@ -240,7 +240,7 @@ byronRestoreBench tr c socketFile = do
seed = SomeMnemonic . unsafeMkMnemonic @15 $ T.words
"involve key curtain arrest fortune custom lens marine before \
\material wheel glide cause weapon wrap"
xprv = Byron.generateKeyFromSeed seed mempty
xprv = Shelley.generateKeyFromSeed seed mempty
wid = WalletId $ digest $ publicKey xprv
wname = WalletName "Benchmark Sequential Wallet"
rngSeed = 0
Expand All @@ -264,11 +264,11 @@ bench_restoration
, WalletKey k
, NFData s
, Show s
, MaxSizeOf Address n ByronKey
, MaxSizeOf Address n ShelleyKey
, PersistState s
, PersistPrivateKey (k 'RootK)
, NetworkDiscriminantVal n
, t ~ IO Byron
, t ~ IO Shelley
)
=> Proxy n
-> Trace IO Text
Expand All @@ -280,13 +280,14 @@ bench_restoration
-- ^ Log output
-> (WalletId, WalletName, s)
-> IO ()
bench_restoration _proxy tracer socketPath np vData progressLogFile (wid, wname, s) = do
bench_restoration proxy tracer socketPath np vData progressLogFile (wid, wname, s) = do
let networkText = networkDiscriminantVal @n
let networkId = networkIdVal proxy
let pm = fromNetworkMagic $ networkMagic $ fst vData
let tl = newTransactionLayer @n @k @(IO Byron) (Proxy) pm
let tl = newTransactionLayer @k @(IO Shelley) networkId
withNetworkLayer nullTracer np socketPath vData $ \nw' -> do
let gp = genesisParameters np
let convert = fromByronBlock gp
let convert = fromCardanoBlock gp
let nw = convert <$> nw'
withBenchDBLayer @s @k tracer (timeInterpreter nw) $ \db -> do
BlockHeader sl _ _ _ <- unsafeRunExceptT $ currentNodeTip nw
Expand Down Expand Up @@ -367,7 +368,7 @@ prepareNode _ socketPath np vData = do
sayErr . fmt $ "Syncing "+|networkDiscriminantVal @n|+" node... "
sl <- withNetworkLayer nullTracer np socketPath vData $ \nw' -> do
let gp = genesisParameters np
let convert = fromByronBlock gp
let convert = fromCardanoBlock gp
let nw = convert <$> nw'
waitForNodeSync nw logQuiet
sayErr . fmt $ "Completed sync of "+|networkDiscriminantVal @n|+" up to "+||sl||+""
Expand Down Expand Up @@ -404,7 +405,7 @@ waitForWalletSync walletLayer wid gp vData = do
-- | Poll the network tip until it reaches the slot corresponding to the current
-- time.
waitForNodeSync
:: NetworkLayer IO (IO Byron) Block
:: NetworkLayer IO (IO Shelley) (CardanoBlock sc)
-> (SlotNo -> SlotNo -> IO ())
-> IO SlotNo
waitForNodeSync nw _logSlot = loop 10
Expand Down
49 changes: 49 additions & 0 deletions lib/shelley/cardano-wallet-shelley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,55 @@ test-suite integration
other-modules:
Cardano.Wallet.Shelley.Faucet

benchmark restore
default-language:
Haskell2010
default-extensions:
NoImplicitPrelude
OverloadedStrings
ghc-options:
-threaded -rtsopts
-Wall
if (flag(release))
ghc-options: -O2 -Werror
build-depends:
base
, bytestring
, cardano-addresses
, cardano-wallet-core
, cardano-wallet-core-integration
, optparse-applicative
, cardano-wallet-shelley
, cardano-wallet-launcher
, ouroboros-network
, contra-tracer
, containers
, criterion-measurement
, cryptonite
, deepseq
, digest
, directory
, filepath
, fmt
, iohk-monitoring
, persistent
, persistent-template
, process
, say
, temporary
, text
, time
, transformers
type:
exitcode-stdio-1.0
hs-source-dirs:
bench
main-is:
Restore.hs
other-modules:
Cardano.Wallet.Primitive.AddressDiscovery.Any
Cardano.Wallet.Primitive.AddressDiscovery.Any.TH

benchmark latency
default-language:
Haskell2010
Expand Down

0 comments on commit 10e76e6

Please sign in to comment.