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

Ensure that transaction tokens are unique in the mempool benchmarks #1095

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,28 @@ launch-*
cabal.project.consensus

ouroboros-consensus-cardano/test/tools-test/disk/chaindb/

# https://github.com/github/gitignore/blob/main/Haskell.gitignore
dist
dist-*
cabal-dev
*.o
*.hi
*.hie
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Control.Monad.Trans.Except (except)
import Data.Set (Set, (\\))
import qualified Data.Set as Set
import Data.TreeDiff (ToExpr)
import Data.Word (Word8)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)
import qualified Ouroboros.Consensus.Block as Block
Expand Down Expand Up @@ -56,7 +55,7 @@ data Tx = Tx {
deriving stock (Eq, Ord, Generic, Show)
deriving anyclass (NoThunks, NFData)

newtype Token = Token { unToken :: Word8 }
newtype Token = Token { unToken :: Int }
deriving stock (Show, Eq, Ord, Generic)
deriving anyclass (NoThunks, ToExpr, Serialise, NFData)

Expand All @@ -81,7 +80,7 @@ sampleLedgerConfig = testBlockLedgerConfigFrom $
-------------------------------------------------------------------------------}

data TestLedgerState = TestLedgerState {
availableTokens :: Set Token
availableTokens :: !(Set Token)
}
deriving stock (Generic, Eq, Show)
deriving anyclass (NoThunks, ToExpr, Serialise)
Expand Down
30 changes: 17 additions & 13 deletions ouroboros-consensus/bench/mempool-bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Bench.Consensus.Mempool
import Bench.Consensus.Mempool.TestBlock (TestBlock)
import qualified Bench.Consensus.Mempool.TestBlock as TestBlock
import Control.Arrow (first)
import Control.Monad (unless, void)
import Control.DeepSeq
import Control.Monad (unless)
import qualified Control.Tracer as Tracer
import Data.Aeson
import qualified Data.ByteString.Lazy as BL
Expand All @@ -27,7 +28,7 @@ import qualified Test.Consensus.Mempool.Mocked as Mocked
import Test.Consensus.Mempool.Mocked (MockedMempool)
import Test.Tasty (withResource)
import Test.Tasty.Bench (CsvPath (CsvPath), bench, benchIngredients,
bgroup, nfIO)
bgroup, whnfIO)
import Test.Tasty.HUnit (testCase, (@?=))
import Test.Tasty.Options (changeOption)
import Test.Tasty.Runners (parseOptions, tryIngredients)
Expand All @@ -50,24 +51,27 @@ main = withStdTerminalHandles $ do
where
benchmarkJustAddingTransactions =
bgroup "Just adding" $
fmap benchAddNTxs [10_000, 1_000_000]
fmap benchAddNTxs [10_000, 20_000]
where
benchAddNTxs n =
withResource
(let txs = mkNTryAddTxs n in fmap (, txs) (openMempoolWithCapacityFor txs))
(pure $!! mkNTryAddTxs n)
(\_ -> pure ())
(\getAcquiredRes -> do
let withAcquiredMempool act = do
(mempool, txs) <- getAcquiredRes
void $ act mempool txs
-- TODO: consider adding a 'reset' command to the mempool to make sure its state is not tainted.
Mocked.removeTxs mempool $ getCmdsTxIds txs
(\getTxs -> do
bgroup (show n <> " transactions") [
bench "benchmark" $ nfIO $ withAcquiredMempool $ \mempool txs -> do
bench "setup mempool" $ whnfIO $ do
txs <- getTxs
openMempoolWithCapacityFor txs
, bench "setup mempool + benchmark" $ whnfIO $ do
txs <- getTxs
mempool <- openMempoolWithCapacityFor txs
run mempool txs
, testCase "test" $ withAcquiredMempool $ \mempool txs ->
, testCase "test" $ do
txs <- getTxs
mempool <- openMempoolWithCapacityFor txs
testAddTxs mempool txs
, testCase "txs length" $ withAcquiredMempool $ \_mempool txs -> do
, testCase "txs length" $ do
txs <- getTxs
length txs @?= n
]
)
Expand Down
Loading