-
Notifications
You must be signed in to change notification settings - Fork 7
Fix micro benchmarks #538
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
Merged
Merged
Fix micro benchmarks #538
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
module Bench.Database.LSMTree.Internal.Merge (benchmarks) where | ||
|
||
import Control.Monad (when, zipWithM) | ||
import Control.Monad (zipWithM) | ||
import Control.RefCount | ||
import Criterion.Main (Benchmark, bench, bgroup) | ||
import qualified Criterion.Main as Cr | ||
import Data.Bifunctor (first) | ||
import qualified Data.BloomFilter.Hash as Hash | ||
import Data.Foldable (traverse_) | ||
import Data.IORef | ||
import qualified Data.List as List | ||
import qualified Data.Map.Strict as Map | ||
import Data.Maybe (fromMaybe) | ||
|
@@ -19,8 +20,7 @@ import Database.LSMTree.Extras.UTxO | |
import Database.LSMTree.Internal.Entry | ||
import Database.LSMTree.Internal.Merge (MergeType (..)) | ||
import qualified Database.LSMTree.Internal.Merge as Merge | ||
import Database.LSMTree.Internal.Paths (RunFsPaths (..), | ||
pathsForRunFiles, runChecksumsPath) | ||
import Database.LSMTree.Internal.Paths (RunFsPaths (..)) | ||
import Database.LSMTree.Internal.Run (Run) | ||
import qualified Database.LSMTree.Internal.Run as Run | ||
import Database.LSMTree.Internal.RunAcc (RunBloomFilterAlloc (..)) | ||
|
@@ -114,7 +114,7 @@ benchmarks = bgroup "Bench.Database.LSMTree.Internal.Merge" [ | |
{ name = "insert-large-keys-x4" -- potentially long keys | ||
, nentries = (totalEntries `div` 10) `splitInto` 4 | ||
, finserts = 1 | ||
, randomKey = first serialiseKey . R.randomByteStringR (6, 4000) | ||
, randomKey = first serialiseKey . R.randomByteStringR (8, 4000) | ||
} | ||
, benchMerge configWord64 | ||
{ name = "insert-mixed-vals-x4" -- potentially long values | ||
|
@@ -201,28 +201,28 @@ benchMerge conf@Config{name} = | |
-- thread `runs` through the environment, too. | ||
-- 2. It forces the result to normal form, which would traverse the | ||
-- whole run, so we force to WHNF ourselves and just return `()`. | ||
|
||
-- We make sure to immediately close resulting runs so we don't run | ||
-- out of file handles or disk space. However, we don't want it to | ||
-- be part of the measurement, as it includes deleting files. | ||
-- Therefore, ... TODO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a dangling TODO here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, that slipped through. Thanks for pointing it out. #547 |
||
Cr.perRunEnvWithCleanup | ||
(pure (runs, outputRunPaths)) | ||
(const (removeOutputRunFiles hasFS)) $ \(runs', p) -> do | ||
!run <- merge hasFS hasBlockIO conf p runs' | ||
-- Make sure to immediately close resulting runs so we don't run | ||
-- out of file handles. Ideally this would not be measured, but at | ||
-- least it's pretty cheap. | ||
releaseRef run | ||
((runs,) <$> newIORef Nothing) | ||
(releaseRun . snd) $ \(runs', ref) -> do | ||
!run <- merge hasFS hasBlockIO conf outputRunPaths runs' | ||
writeIORef ref $ Just $ releaseRef run | ||
] | ||
where | ||
withEnv = | ||
Cr.envWithCleanup | ||
(mergeEnv conf) | ||
mergeEnvCleanup | ||
|
||
-- We need to keep the input runs, but remove the freshly created one. | ||
removeOutputRunFiles :: FS.HasFS IO FS.HandleIO -> IO () | ||
removeOutputRunFiles hasFS = do | ||
traverse_ (FS.removeFile hasFS) (pathsForRunFiles outputRunPaths) | ||
exists <- FS.doesFileExist hasFS (runChecksumsPath outputRunPaths) | ||
when exists $ | ||
FS.removeFile hasFS (runChecksumsPath outputRunPaths) | ||
releaseRun :: IORef (Maybe (IO ())) -> IO () | ||
releaseRun ref = | ||
readIORef ref >>= \case | ||
Nothing -> pure () | ||
Just release -> release | ||
|
||
merge :: | ||
FS.HasFS IO FS.HandleIO | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can generate much smaller blobs. It would speed up the benchmark setup, and the performance of the lookups code does not depend on the blob size. But it's maybe also not super important because inserts with blobs are generated only rarely