This commit is contained in:
Dmitry Zuikov 2023-01-26 08:54:41 +03:00
parent e7ce36591a
commit 5c4fbca977
1 changed files with 37 additions and 29 deletions

View File

@ -10,12 +10,14 @@ import Control.Concurrent.Async
import Control.Monad import Control.Monad
import Data.ByteString.Lazy (ByteString) import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy.Char8 qualified as B8 import Data.ByteString.Lazy.Char8 qualified as B8
import Data.Fixed
import Data.Functor import Data.Functor
import qualified Data.Vector.Unboxed as U import qualified Data.Vector.Unboxed as U
import System.FilePath.Posix
import System.IO.Temp import System.IO.Temp
import System.Random.MWC import System.Random.MWC
import System.Random.Shuffle import System.Random.Shuffle
import System.FilePath.Posix import System.TimeIt
import Data.List qualified as L import Data.List qualified as L
import Prettyprinter import Prettyprinter
@ -29,6 +31,8 @@ main = do
g <- initialize $ U.fromList [0xFAFA, 0xBEBE, 0xC0C0] g <- initialize $ U.fromList [0xFAFA, 0xBEBE, 0xC0C0]
bytes <- B8.pack <$> replicateM size (uniformM g)
withSystemTempDirectory "cww-test" $ \dir -> do withSystemTempDirectory "cww-test" $ \dir -> do
let opts = [ StoragePrefix (dir </> ".test-cww") let opts = [ StoragePrefix (dir </> ".test-cww")
@ -36,24 +40,29 @@ main = do
storage <- simpleStorageInit opts :: IO (SimpleStorage HbSync) storage <- simpleStorageInit opts :: IO (SimpleStorage HbSync)
w1 <- replicateM 1 $ async (simpleStorageWorker storage) w1 <- replicateM 2 $ async (simpleStorageWorker storage)
cw <- newChunkWriterIO storage (Just (dir </> ".qqq")) cw <- newChunkWriterIO storage (Just (dir </> ".qqq"))
w2 <- replicateM 1 $ async $ runChunkWriter cw w2 <- replicateM 2 $ async $ runChunkWriter cw
failed <- replicateM 100 $ do let times = 100
let info = show $ "writing" <+> pretty (show (realToFrac size / 1024 :: Fixed E2))
<+> "mb"
<+> pretty times <+> "times"
timeItNamed info $ do
failed <- replicateM times $ do
bytes <- B8.pack <$> (replicateM size $ uniformM g)
let hash = hashObject bytes let hash = hashObject bytes
let psz = calcChunks (fromIntegral size) (fromIntegral chu) let psz = calcChunks (fromIntegral size) (fromIntegral chu)
psz' <- shuffleM psz psz' <- shuffleM psz
-- psz' <- pure psz
-- forConcurrently_ psz' $ \(o,s) -> do
forConcurrently_ psz' $ \(o,s) -> do forConcurrently_ psz' $ \(o,s) -> do
let t = B8.take s $ B8.drop o bytes let t = B8.take s $ B8.drop o bytes
writeChunk cw 1 hash (fromIntegral o) t writeChunk cw 1 hash (fromIntegral o) t
@ -70,6 +79,5 @@ main = do
print $ "failed" <+> pretty (sum (mconcat failed)) print $ "failed" <+> pretty (sum (mconcat failed))
pure ()