Skip to content

Commit 6b10372

Browse files
committed
[lmdb facebookincubator#4] Add support for LMDB in benchmarks
1 parent 0dfd773 commit 6b10372

7 files changed

Lines changed: 40 additions & 10 deletions

File tree

glean.cabal.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,7 @@ library bench-lib
18841884
BenchDB
18851885
build-depends:
18861886
glean:backend-api,
1887+
glean:bench-util,
18871888
glean:client-hs,
18881889
glean:core,
18891890
glean:db,

glean/bench/BenchDB.hs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import qualified Data.Text as Text
1616

1717
import Glean
1818
import Glean.Backend.Types (loadPredicates)
19-
import Glean.Database.Test (withEmptyTestDB, completeTestDB)
19+
import Glean.Database.Test
2020
import Glean.Database.Open
2121
import Glean.Database.Write.Batch
2222
import qualified Glean.Schema.Sys.Types as Sys
@@ -26,9 +26,20 @@ import qualified Glean.Schema.Sys as Sys
2626
import qualified Glean.Schema.Cxx1 as Cxx
2727
import qualified Glean.Schema.GleanTest as Glean.Test
2828
import Glean.Typed
29+
import Glean.Util.Benchmark
2930

30-
withBenchDB :: Int -> (forall b . Backend b => b -> Repo -> IO a) -> IO a
31-
withBenchDB num act = withEmptyTestDB [] $ \env repo -> do
31+
withBenchDB
32+
:: GleanBenchConfig
33+
-> Int
34+
-> (forall b . Backend b => b -> Repo -> IO a)
35+
-> IO a
36+
withBenchDB conf num act = do
37+
let
38+
settings
39+
| useLMDB conf = [setLMDBStorage]
40+
| otherwise = []
41+
42+
withEmptyTestDB settings $ \env repo -> do
3243
withOpenDatabase env repo $ \odb ->
3344
void $ return odb
3445

glean/bench/MakeFactBench.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Glean.Util.Benchmark
2121
import Glean.Typed
2222

2323
main :: IO ()
24-
main = benchmarkMain $ \run -> do
24+
main = benchmarkMain $ \_conf run -> do
2525
withEmptyTestDB [] $ \env repo -> do
2626
predicates <- Backend.loadPredicates env repo
2727
[ Cxx.allPredicates

glean/bench/QueryBench.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import Glean.Util.Benchmark
2929
import BenchDB
3030

3131
main :: IO ()
32-
main = benchmarkMain $ \run -> withBenchDB 10000 $ \env repo -> do
32+
main = benchmarkMain $ \conf run ->
33+
withBenchDB conf 10000 $ \env repo -> do
3334
let
3435
nestedAngle :: Query Cxx.FunctionName
3536
nestedAngle = angle "cxx1.FunctionName { name = \"x1\" }"

glean/bench/RenameBench.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Glean.Util.Benchmark
2222
import TestBatch
2323

2424
main :: IO ()
25-
main = benchmarkMain $ \run ->
25+
main = benchmarkMain $ \_conf run ->
2626
withEmptyTestDB [] $ \env repo -> do
2727
schema <- loadDbSchema env repo
2828
batch <- testBatch 500000 env repo

glean/bench/lib/Glean/Util/Benchmark.hs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,31 @@
99
module Glean.Util.Benchmark
1010
( BenchmarkRunner
1111
, benchmarkMain
12+
, GleanBenchConfig(..)
1213
) where
1314

1415
import Criterion.Main
1516
import Criterion.Main.Options
17+
import Data.Default
18+
import Options.Applicative
1619

1720
import Glean.Init
1821

1922
type BenchmarkRunner = [Benchmark] -> IO ()
2023

21-
benchmarkMain :: (BenchmarkRunner -> IO ()) -> IO ()
22-
benchmarkMain exec = withOptions (describe defaultConfig) $
23-
exec . runMode
24+
benchmarkMain :: (GleanBenchConfig -> BenchmarkRunner -> IO ()) -> IO ()
25+
benchmarkMain exec =
26+
withOptions
27+
(describeWith ((,) <$> opts <*> parseWith defaultConfig)) $ \(conf, crit) ->
28+
exec conf (runMode crit)
29+
30+
data GleanBenchConfig = GleanBenchConfig {
31+
useLMDB :: Bool
32+
}
33+
34+
instance Default GleanBenchConfig where
35+
def = GleanBenchConfig { useLMDB = False }
36+
37+
opts :: Parser GleanBenchConfig
38+
opts = GleanBenchConfig
39+
<$> switch (long "lmdb" <> help "use LMDB (otherwise use RocksDB)")

glean/test/tests/TimeoutTest.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{-# LANGUAGE QuasiQuotes #-}
1010
module TimeoutTest (main) where
1111

12+
import Data.Default
1213
import Test.HUnit
1314

1415
import TestRunner
@@ -21,7 +22,7 @@ import qualified Glean.Schema.GleanTest.Types as Glean.Test
2122
import BenchDB
2223

2324
timeoutTest :: Test
24-
timeoutTest = TestCase $ withBenchDB 10000 $ \env repo -> do
25+
timeoutTest = TestCase $ withBenchDB def 10000 $ \env repo -> do
2526
-- The test spends most of its time building the DB (withBenchDB above),
2627
-- so to keep things reasonable in debug mode we limit the number of
2728
-- facts to 10K and set the time limit to 1ms which is as low as we

0 commit comments

Comments
 (0)