On Tue, Dec 13, 2011 at 4:55 AM, Anatoly Yakovenko <[email protected]> wrote: > So I am trying to understand how acid state works. The HelloWorld > example has a > > type Message = String > data Database = Database [Message] > > $(deriveSafeCopy 0 'base ''Database) > > -- Transactions are defined to run in either the 'Update' monad > -- or the 'Query' monad. > addMessage :: Message -> Update Database () > addMessage msg > = do Database messages <- get > put $ Database (msg:messages) > > > It seems to me that since the Dababase is a list of messages every > update would require acid-state to rewrite the list into the file, so > each update would get slower as the list gets bigger, but what I am > seeing is that updates are constant time regardless of the size of the > list. So how does it work?
acid-state doesn't write the whole thing to the disk every time there's a transaction. Instead, it just writes the transaction on a transaction log. So it will just write something like "AddMessage msg" to the disk. Periodically, checkpoints are created which *do* have all your data inside them (but even so, checkpoints are written asynchronously). Cheers, -- Felipe. _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
