acid-state 0.11.1 → 0.11.2
raw patch · 3 files changed
+126/−3 lines, 3 filesdep +acid-statedep +criteriondep +randomdep ~basedep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependencies added: acid-state, criterion, random, system-fileio, system-filepath
Dependency ranges changed: base, bytestring
API changes (from Hackage documentation)
Files
- acid-state.cabal +47/−2
- benchmarks/loading/Benchmark.hs +78/−0
- src/Data/Acid/Log.hs +1/−1
acid-state.cabal view
@@ -1,5 +1,5 @@ Name: acid-state-Version: 0.11.1+Version: 0.11.2 Synopsis: Add ACID guarantees to any serializable Haskell data structure. Description: Use regular Haskell data structures as your database and get stronger ACID guarantees than most RDBMS offer. Homepage: http://acid-state.seize.it/@@ -9,7 +9,7 @@ -- Copyright: Category: Database Build-type: Simple-Cabal-version: >=1.6+Cabal-version: >=1.10 Extra-source-files: examples/*.hs examples/errors/*.hs@@ -57,4 +57,49 @@ else Hs-Source-Dirs: src-unix/ + default-language: Haskell2010 GHC-Options: -fwarn-unused-imports -fwarn-unused-binds++++benchmark loading-benchmark+ type:+ exitcode-stdio-1.0+ hs-source-dirs:+ benchmarks/loading+ main-is:+ Benchmark.hs+ build-depends:+ random,+ directory,+ system-fileio == 0.3.*,+ system-filepath,+ criterion == 0.8.*,+ mtl,+ base,+ acid-state+ default-language:+ Haskell2010+ default-extensions: + PatternGuards+ GADTs+ StandaloneDeriving+ MultiParamTypeClasses+ ScopedTypeVariables+ FlexibleInstances+ TypeFamilies+ TypeOperators+ FlexibleContexts+ NoImplicitPrelude+ EmptyDataDecls+ DataKinds+ NoMonomorphismRestriction+ RankNTypes+ ConstraintKinds+ DefaultSignatures+ TupleSections+ TemplateHaskell+ OverloadedStrings+ DeriveDataTypeable+ ghc-options:+ -O2
+ benchmarks/loading/Benchmark.hs view
@@ -0,0 +1,78 @@++import Benchmark.Prelude+import Criterion.Main+import qualified Data.Acid as Acid+import qualified Benchmark.FileSystem as FS+import qualified Benchmark.Model as Model; import Benchmark.Model (Model)+import qualified System.Random as Random++++main :: IO ()+main = do+ + workingPath <- do + workingPath <- FS.getTemporaryDirectory+ rndStr <- replicateM 16 $ Random.randomRIO ('a', 'z')+ return $ workingPath <> "acid-state" <> "benchmarks" <> "loading" <> FS.decodeString rndStr++ putStrLn $ "Working under the following temporary directory: " ++ FS.encodeString workingPath+ FS.removeTreeIfExists workingPath+ FS.createTree workingPath++ defaultMain =<< sequence+ [+ prepareBenchmarksGroup workingPath $ 200,+ prepareBenchmarksGroup workingPath $ 400,+ prepareBenchmarksGroup workingPath $ 600,+ prepareBenchmarksGroup workingPath $ 800+ ]++++prepareBenchmarksGroup :: FS.FilePath -> Int -> IO Benchmark+prepareBenchmarksGroup workingPath size = do+ putStrLn $ "Preparing instances for size " ++ show size++ let+ workingPath' = workingPath <> (FS.decodeString $ show size)+ logsInstancePath = workingPath' <> "logs-instance"+ checkpointInstancePath = workingPath' <> "checkpoint-instance"++ FS.createTree logsInstancePath+ FS.createTree checkpointInstancePath+ + putStrLn "Initializing"+ inst <- initialize checkpointInstancePath size+ + putStrLn "Copying"+ FS.copy checkpointInstancePath logsInstancePath+ FS.removeFile $ logsInstancePath <> "open.lock"++ putStrLn "Checkpointing"+ Acid.createCheckpoint inst++ putStrLn "Closing"+ Acid.closeAcidState inst++ return $ bgroup (show size) + [+ bench "From Logs" $ nfIO $ + load logsInstancePath >>= Acid.closeAcidState,+ bench "From Checkpoint" $ nfIO $ + load checkpointInstancePath >>= Acid.closeAcidState+ ]++++load :: FS.FilePath -> IO (Acid.AcidState Model)+load path = Acid.openLocalStateFrom (FS.encodeString path) mempty++initialize :: FS.FilePath -> Int -> IO (Acid.AcidState Model)+initialize path size = do+ inst <- Acid.openLocalStateFrom (FS.encodeString path) mempty+ let values = replicate size $ replicate 100 $ replicate 100 1+ mapM_ (Acid.update inst . Model.Insert) values+ return inst++
src/Data/Acid/Log.hs view
@@ -292,7 +292,7 @@ worker files where worker [] = return Nothing worker (logFile:logFiles)- = do archive <- Lazy.readFile logFile+ = do archive <- fmap Lazy.fromStrict $ Strict.readFile logFile case Archive.readEntries archive of Done -> worker logFiles Next entry next -> return $ Just (decode' (lastEntry entry next))