@@ -160,8 +160,7 @@ data RunOpts = RunOpts
160160 , batchSize :: ! Int
161161 , check :: ! Bool
162162 , seed :: ! Word64
163- , pipelined :: ! Bool
164- , lookuponly :: ! Bool
163+ , mode :: ! RunMode
165164 }
166165 deriving stock Show
167166
@@ -189,21 +188,27 @@ mkTableConfigSetup GlobalOpts{diskCachePolicy}
189188 }
190189
191190mkTableConfigRun :: GlobalOpts -> RunOpts -> LSM. TableConfig -> LSM. TableConfig
192- mkTableConfigRun GlobalOpts {diskCachePolicy} RunOpts {pipelined } conf =
191+ mkTableConfigRun GlobalOpts {diskCachePolicy} RunOpts {mode } conf =
193192 conf {
194193 LSM. confDiskCachePolicy = diskCachePolicy,
195- LSM. confMergeBatchSize = if pipelined
196- then LSM. MergeBatchSize 1
197- else LSM. confMergeBatchSize conf
194+ LSM. confMergeBatchSize =
195+ case mode of
196+ Sequential -> LSM. confMergeBatchSize conf
197+ Pipelined -> LSM. MergeBatchSize 1
198+ LookupOnly -> LSM. confMergeBatchSize conf
199+ UpdateOnly -> LSM. confMergeBatchSize conf
198200 }
199201
200202mkTableConfigOverride :: GlobalOpts -> RunOpts -> LSM. TableConfigOverride
201- mkTableConfigOverride GlobalOpts {diskCachePolicy} RunOpts {pipelined } =
203+ mkTableConfigOverride GlobalOpts {diskCachePolicy} RunOpts {mode } =
202204 LSM. noTableConfigOverride {
203205 LSM. overrideDiskCachePolicy = Just diskCachePolicy,
204- LSM. overrideMergeBatchSize = if pipelined
205- then Just (LSM. MergeBatchSize 1 )
206- else Nothing
206+ LSM. overrideMergeBatchSize =
207+ case mode of
208+ Sequential -> Nothing
209+ Pipelined -> Just $ LSM. MergeBatchSize 1
210+ LookupOnly -> Nothing
211+ UpdateOnly -> Nothing
207212 }
208213
209214mkTracer :: GlobalOpts -> Tracer IO LSM. LSMTreeTrace
@@ -269,8 +274,23 @@ runOptsP = pure RunOpts
269274 <*> O. option O. auto (O. long " batch-size" <> O. value 256 <> O. showDefault <> O. help " Batch size" )
270275 <*> O. switch (O. long " check" <> O. help " Check generated key distribution" )
271276 <*> O. option O. auto (O. long " seed" <> O. value 1337 <> O. showDefault <> O. help " Random seed" )
272- <*> O. switch (O. long " pipelined" <> O. help " Use pipelined mode" )
273- <*> O. switch (O. long " lookup-only" <> O. help " Use lookup only mode" )
277+ <*> O. option O. auto (O. long " mode" <> O. value Sequential <> O. showDefault
278+ <> O. help " Mode [Sequential | Pipelined | LookupOnly | UpdateOnly]" )
279+
280+ -- | The run mode affects the method of performing
281+ data RunMode =
282+ -- | Use sequential mode: wait for a batch of operations to complete before
283+ -- starting the next one.
284+ Sequential
285+ -- | Use pipelined mode: overlap batches of operations.
286+ | Pipelined
287+ -- | Use lookup-only sequential mode: like sequential mode, but only perform
288+ -- the lookups and not the updates.
289+ | LookupOnly
290+ -- | Use update-only sequential mode: like sequential mode, but only perform
291+ -- the updates and not the lookups.
292+ | UpdateOnly
293+ deriving stock (Show , Eq , Read )
274294
275295deriving stock instance Read LSM. DiskCachePolicy
276296deriving stock instance Read LSM. BloomFilterAlloc
@@ -613,17 +633,18 @@ doRun gopts opts =
613633 checkvar <- newIORef $ pureReference
614634 (initialSize gopts) (batchSize opts)
615635 (batchCount opts) (seed opts)
616- let fcheck | not (check opts) = \ _ _ -> pure ()
636+ let fcheck | not (check opts) || mode opts == UpdateOnly = \ _ _ -> pure ()
617637 | otherwise = \ b y -> do
618638 (x: xs) <- readIORef checkvar
619639 unless (x == y) $
620640 fail $ " lookup result mismatch in batch " ++ show b
621641 writeIORef checkvar xs
622642
623- let benchmarkIterations
624- | pipelined opts = pipelinedIterations h
625- | lookuponly opts= sequentialIterationsLO
626- | otherwise = sequentialIterations h
643+ let benchmarkIterations = case mode opts of
644+ Sequential -> sequentialIterations h
645+ Pipelined -> pipelinedIterations h
646+ LookupOnly -> sequentialIterationsLO
647+ UpdateOnly -> sequentialIterationsUO
627648 ! progressInterval = max 1 ((batchCount opts) `div` 100 )
628649 madeProgress b = b `mod` progressInterval == 0
629650 (time, _, _) <- timed_ $ do
@@ -673,7 +694,6 @@ sequentialIteration h output !initialSize !batchSize !tbl !b !g =
673694 -- continue to the next batch
674695 pure g'
675696
676-
677697sequentialIterations :: LatencyHandle
678698 -> (Int -> LookupResults -> IO () )
679699 -> Int -> Int -> Int -> Word64
@@ -715,6 +735,38 @@ sequentialIterationsLO output !initialSize !batchSize !batchCount !seed !tbl =
715735 where
716736 g0 = initGen initialSize batchSize batchCount seed
717737
738+ {-# INLINE sequentialIterationUO #-}
739+ sequentialIterationUO ::
740+ (Int -> LookupResults -> IO () )
741+ -> Int
742+ -> Int
743+ -> LSM. Table IO K V B
744+ -> Int
745+ -> MCG. MCG
746+ -> IO MCG. MCG
747+ sequentialIterationUO output ! initialSize ! batchSize ! tbl ! b ! g = do
748+ let (! g', _ls, is) = generateBatch initialSize batchSize g b
749+
750+ -- lookups
751+ output b V. empty
752+
753+ -- deletes and inserts
754+ _ <- LSM. updates tbl is
755+
756+ -- continue to the next batch
757+ pure g'
758+
759+ sequentialIterationsUO ::
760+ (Int -> LookupResults -> IO () )
761+ -> Int -> Int -> Int -> Word64
762+ -> LSM. Table IO K V B
763+ -> IO ()
764+ sequentialIterationsUO output ! initialSize ! batchSize ! batchCount ! seed ! tbl = do
765+ void $ forFoldM_ g0 [ 0 .. batchCount - 1 ] $ \ b g ->
766+ sequentialIterationUO output initialSize batchSize tbl b g
767+ where
768+ g0 = initGen initialSize batchSize batchCount seed
769+
718770-------------------------------------------------------------------------------
719771-- pipelined
720772-------------------------------------------------------------------------------
0 commit comments