Skip to content

Commit 356d988

Browse files
committed
QLS tests: label the logical size of tables
Initial results: Table sizes (440 in total): 41.1% TableSize "n == 0" 21.1% TableSize "32 <= n < 64" 13.4% TableSize "16 <= n < 32" 8.9% TableSize "8 <= n < 16" 7.5% TableSize "64 <= n < 128" 2.7% TableSize "4 <= n < 8" 2.3% TableSize "128 <= n < 256" 2.0% TableSize "2 <= n < 4" 0.7% TableSize "1 <= n < 2" 0.2% TableSize "256 <= n < 512" Again, it's not great that 40% of tables are empty. We'll try and improve that. On the othe hand, the long tail is quite long, going out over 100 elements.
1 parent 3d2a346 commit 356d988

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

test/Database/LSMTree/Model/Normal.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module Database.LSMTree.Model.Normal (
3030
, snapshot
3131
-- * Multiple writable table handles
3232
, duplicate
33+
-- * Testing
34+
, size
3335
) where
3436

3537
import qualified Crypto.Hash.SHA256 as SHA256
@@ -61,6 +63,9 @@ type role Table nominal nominal nominal
6163
empty :: Table k v blob
6264
empty = Table Map.empty
6365

66+
size :: Table k v blob -> Int
67+
size (Table m) = Map.size m
68+
6469
-- | This instance is for testing and debugging only.
6570
instance
6671
(SerialiseKey k, SerialiseValue v, SerialiseValue blob)

test/Database/LSMTree/Model/Normal/Session.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ module Database.LSMTree.Model.Normal.Session (
2424
Model (..)
2525
, initModel
2626
, UpdateCounter (..)
27-
-- ** SomeTable
27+
-- ** SomeTable, for testing
2828
, SomeTable (..)
2929
, toSomeTable
3030
, fromSomeTable
31+
, withSomeTable
3132
, TableHandleID
3233
, tableHandleID
34+
, Model.size
3335
-- ** Constraints
3436
, C
3537
, C_
@@ -139,6 +141,13 @@ fromSomeTable ::
139141
-> Maybe (Model.Table k v blob)
140142
fromSomeTable (SomeTable tbl) = cast tbl
141143

144+
withSomeTable ::
145+
(forall k v blob. (Typeable k, Typeable v, Typeable blob)
146+
=> Model.Table k v blob -> a)
147+
-> SomeTable
148+
-> a
149+
withSomeTable f (SomeTable tbl) = f tbl
150+
142151
newtype SomeCursor = SomeCursor Dynamic
143152

144153
instance Show SomeCursor where

test/Test/Database/LSMTree/Normal/StateMachine.hs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,12 +673,13 @@ instance ( Eq (Class.TableConfig h)
673673
-> ModelLookUp (ModelState h)
674674
-> ModelState h
675675
-> (ModelValue (ModelState h) a, ModelState h)
676-
modelNextState action lookUp (ModelState mock stats) =
677-
auxStats $ runModel lookUp action mock
676+
modelNextState action lookUp (ModelState state stats) =
677+
auxStats $ runModel lookUp action state
678678
where
679679
auxStats :: (Val h a, Model.Model) -> (Val h a, ModelState h)
680-
auxStats (result, state') =
681-
(result, ModelState state' $ updateStats action lookUp result stats)
680+
auxStats (result, state') = (result, ModelState state' stats')
681+
where
682+
stats' = updateStats action lookUp state state' result stats
682683

683684
usedVars :: LockstepAction (ModelState h) a -> [AnyGVar (ModelOp (ModelState h))]
684685
usedVars = \case
@@ -1315,6 +1316,10 @@ data Stats = Stats {
13151316
-- === Final tags (per action sequence, per table)
13161317
-- | Number of actions per table (succesful or failing)
13171318
, numActionsPerTable :: !(Map Model.TableHandleID Int)
1319+
-- | The size of tables that were closed. This is used to augment the table
1320+
-- sizes from the final model state (which of course has only tables still
1321+
-- open in the final state).
1322+
, closedTableSizes :: !(Map Model.TableHandleID Int)
13181323
}
13191324
deriving stock Show
13201325

@@ -1329,6 +1334,7 @@ initStats = Stats {
13291334
, successActions = []
13301335
, failActions = []
13311336
, numActionsPerTable = Map.empty
1337+
, closedTableSizes = Map.empty
13321338
}
13331339

13341340
updateStats ::
@@ -1340,10 +1346,12 @@ updateStats ::
13401346
)
13411347
=> LockstepAction (ModelState h) a
13421348
-> ModelLookUp (ModelState h)
1349+
-> Model.Model
1350+
-> Model.Model
13431351
-> Val h a
13441352
-> Stats
13451353
-> Stats
1346-
updateStats action lookUp result =
1354+
updateStats action lookUp modelBefore _modelAfter result =
13471355
-- === Tags
13481356
updNewTableTypes
13491357
. updSnapshotted
@@ -1353,6 +1361,7 @@ updateStats action lookUp result =
13531361
. updSuccessActions
13541362
. updFailActions
13551363
. updNumActionsPerTable
1364+
. updClosedTableSizes
13561365
where
13571366
-- === Tags
13581367

@@ -1477,6 +1486,18 @@ updateStats action lookUp result =
14771486
(numActionsPerTable stats)
14781487
}
14791488

1489+
updClosedTableSizes stats = case action of
1490+
Close tableVar
1491+
| MTableHandle th <- lookUp tableVar
1492+
, let tid = Model.tableHandleID th
1493+
-- This lookup can fail if the table was already closed:
1494+
, Just (_, table) <- Map.lookup tid (Model.tableHandles modelBefore)
1495+
, let tsize = Model.withSomeTable Model.size table
1496+
-> stats {
1497+
closedTableSizes = Map.insert tid tsize (closedTableSizes stats)
1498+
}
1499+
_ -> stats
1500+
14801501
getTableHandleId :: ModelValue (ModelState h) (WrapTableHandle h IO k v blob)
14811502
-> Model.TableHandleID
14821503
getTableHandleId (MTableHandle th) = Model.tableHandleID th
@@ -1594,18 +1615,19 @@ data FinalTag =
15941615
-- | Number of actions on each table
15951616
| NumTableActions String
15961617
-- | Total /logical/ size of a table
1597-
| TableSize String -- TODO: implement
1618+
| TableSize String
15981619
deriving stock Show
15991620

16001621
-- | This is run only after completing every action
16011622
tagFinalState' :: Lockstep (ModelState h) -> [(String, [FinalTag])]
1602-
tagFinalState' (getModel -> ModelState _ finalStats) = concat [
1623+
tagFinalState' (getModel -> ModelState finalState finalStats) = concat [
16031624
tagNumLookupsResults
16041625
, tagNumUpdates
16051626
, tagSuccessActions
16061627
, tagFailActions
16071628
, tagNumTables
16081629
, tagNumTableActions
1630+
, tagTableSizes
16091631
]
16101632
where
16111633
tagNumLookupsResults = [
@@ -1640,6 +1662,15 @@ tagFinalState' (getModel -> ModelState _ finalStats) = concat [
16401662
| n <- Map.elems (numActionsPerTable finalStats)
16411663
]
16421664

1665+
tagTableSizes =
1666+
[ ("Table sizes", [ TableSize (showPowersOf 2 size) ])
1667+
| let openSizes, closedSizes :: Map Model.TableHandleID Int
1668+
openSizes = Model.withSomeTable Model.size . snd <$>
1669+
Model.tableHandles finalState
1670+
closedSizes = closedTableSizes finalStats
1671+
, size <- Map.elems (openSizes `Map.union` closedSizes)
1672+
]
1673+
16431674
{-------------------------------------------------------------------------------
16441675
Utils
16451676
-------------------------------------------------------------------------------}

0 commit comments

Comments
 (0)