addDb (FsckHandle h _) k = H.queueDb h checkcommit $
void $ insertUnique $ Fscked k
where
- -- commit queue after 1000 files or 5 minutes, whichever comes first
+ -- Commit queue after 1000 changes or 5 minutes, whichever comes first.
+ -- The time based commit allows for an incremental fsck to be
+ -- interrupted and not lose much work.
checkcommit sz lastcommittime
| sz > 1000 = return True
| otherwise = do
import Database.Persist.Sql hiding (Key)
import Database.Persist.TH
-import Data.Time.Clock
import Control.Monad
import Data.Maybe
queueDb :: SqlPersistM () -> WriteHandle -> IO ()
queueDb a (WriteHandle h) = H.queueDb h checkcommit a
where
- -- commit queue after 1000 changes or 5 minutes, whichever comes first
- checkcommit sz lastcommittime
- | sz > 1000 = return True
- | otherwise = do
- now <- getCurrentTime
- return $ diffUTCTime now lastcommittime > 300
+ -- commit queue after 1000 changes
+ checkcommit sz _lastcommittime = pure (sz > 1000)
addAssociatedFile :: Key -> TopFilePath -> WriteHandle -> IO ()
addAssociatedFile k f = queueDb $ do
[[!meta author=yoh]]
[[!tag projects/datalad]]
+
+> I think I've improved this all that it can reasonably be sped up,
+> so [[done]]. --[[Joey]]
--- /dev/null
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 13"""
+ date="2021-05-31T18:40:59Z"
+ content="""
+There was an unncessary check of the current time per sql insert, removing
+that sped it up by 3 seconds in my benchmark.
+
+Also tried increasing the number of inserts per sqlite transaction from 1k
+to 10k. Memory use increased to 90 mb, but no measurable speed increase.
+
+I don't see much else that can speed up the sqlite part, without going deep
+into the weeds of populating sqlite databases without using sql, or using
+multi-value inserts ([like described here](https://medium.com/@JasonWyatt/squeezing-performance-from-sqlite-insertions-971aff98eef2).
+Both would prevent using persistent to abstract sql away, and would
+only be usable in this case, not speeding up git-annex generally,
+so not too enthused.
+"""]]