Skip to content

Commit fbf86c7

Browse files
authored
Ensure that transaction tokens are unique in the mempool benchmarks (#1095)
2 parents 2a7adde + 9f7a6ef commit fbf86c7

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,28 @@ launch-*
7272
cabal.project.consensus
7373

7474
ouroboros-consensus-cardano/test/tools-test/disk/chaindb/
75+
76+
# https://github.com/github/gitignore/blob/main/Haskell.gitignore
77+
dist
78+
dist-*
79+
cabal-dev
80+
*.o
81+
*.hi
82+
*.hie
83+
*.chi
84+
*.chs.h
85+
*.dyn_o
86+
*.dyn_hi
87+
.hpc
88+
.hsenv
89+
.cabal-sandbox/
90+
cabal.sandbox.config
91+
*.prof
92+
*.aux
93+
*.hp
94+
*.eventlog
95+
.stack-work/
96+
cabal.project.local
97+
cabal.project.local~
98+
.HTF/
99+
.ghc.environment.*

ouroboros-consensus/bench/mempool-bench/Bench/Consensus/Mempool/TestBlock.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Control.Monad.Trans.Except (except)
2828
import Data.Set (Set, (\\))
2929
import qualified Data.Set as Set
3030
import Data.TreeDiff (ToExpr)
31-
import Data.Word (Word8)
3231
import GHC.Generics (Generic)
3332
import NoThunks.Class (NoThunks)
3433
import qualified Ouroboros.Consensus.Block as Block
@@ -56,7 +55,7 @@ data Tx = Tx {
5655
deriving stock (Eq, Ord, Generic, Show)
5756
deriving anyclass (NoThunks, NFData)
5857

59-
newtype Token = Token { unToken :: Word8 }
58+
newtype Token = Token { unToken :: Int }
6059
deriving stock (Show, Eq, Ord, Generic)
6160
deriving anyclass (NoThunks, ToExpr, Serialise, NFData)
6261

@@ -81,7 +80,7 @@ sampleLedgerConfig = testBlockLedgerConfigFrom $
8180
-------------------------------------------------------------------------------}
8281

8382
data TestLedgerState = TestLedgerState {
84-
availableTokens :: Set Token
83+
availableTokens :: !(Set Token)
8584
}
8685
deriving stock (Generic, Eq, Show)
8786
deriving anyclass (NoThunks, ToExpr, Serialise)

ouroboros-consensus/bench/mempool-bench/Main.hs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import Bench.Consensus.Mempool
1111
import Bench.Consensus.Mempool.TestBlock (TestBlock)
1212
import qualified Bench.Consensus.Mempool.TestBlock as TestBlock
1313
import Control.Arrow (first)
14-
import Control.Monad (unless, void)
14+
import Control.DeepSeq
15+
import Control.Monad (unless)
1516
import qualified Control.Tracer as Tracer
1617
import Data.Aeson
1718
import qualified Data.ByteString.Lazy as BL
@@ -27,7 +28,7 @@ import qualified Test.Consensus.Mempool.Mocked as Mocked
2728
import Test.Consensus.Mempool.Mocked (MockedMempool)
2829
import Test.Tasty (withResource)
2930
import Test.Tasty.Bench (CsvPath (CsvPath), bench, benchIngredients,
30-
bgroup, nfIO)
31+
bgroup, whnfIO)
3132
import Test.Tasty.HUnit (testCase, (@?=))
3233
import Test.Tasty.Options (changeOption)
3334
import Test.Tasty.Runners (parseOptions, tryIngredients)
@@ -50,24 +51,27 @@ main = withStdTerminalHandles $ do
5051
where
5152
benchmarkJustAddingTransactions =
5253
bgroup "Just adding" $
53-
fmap benchAddNTxs [10_000, 1_000_000]
54+
fmap benchAddNTxs [10_000, 20_000]
5455
where
5556
benchAddNTxs n =
5657
withResource
57-
(let txs = mkNTryAddTxs n in fmap (, txs) (openMempoolWithCapacityFor txs))
58+
(pure $!! mkNTryAddTxs n)
5859
(\_ -> pure ())
59-
(\getAcquiredRes -> do
60-
let withAcquiredMempool act = do
61-
(mempool, txs) <- getAcquiredRes
62-
void $ act mempool txs
63-
-- TODO: consider adding a 'reset' command to the mempool to make sure its state is not tainted.
64-
Mocked.removeTxs mempool $ getCmdsTxIds txs
60+
(\getTxs -> do
6561
bgroup (show n <> " transactions") [
66-
bench "benchmark" $ nfIO $ withAcquiredMempool $ \mempool txs -> do
62+
bench "setup mempool" $ whnfIO $ do
63+
txs <- getTxs
64+
openMempoolWithCapacityFor txs
65+
, bench "setup mempool + benchmark" $ whnfIO $ do
66+
txs <- getTxs
67+
mempool <- openMempoolWithCapacityFor txs
6768
run mempool txs
68-
, testCase "test" $ withAcquiredMempool $ \mempool txs ->
69+
, testCase "test" $ do
70+
txs <- getTxs
71+
mempool <- openMempoolWithCapacityFor txs
6972
testAddTxs mempool txs
70-
, testCase "txs length" $ withAcquiredMempool $ \_mempool txs -> do
73+
, testCase "txs length" $ do
74+
txs <- getTxs
7175
length txs @?= n
7276
]
7377
)

0 commit comments

Comments
 (0)