Closed
Description
Proposal
- Add a
Sync(prefix Key)
function to theDatastore
interface.- This function will be a no-op when the datastore is in synchronous mode (the default).
- Otherwise,
Sync(prefix)
guarantees that anyPut(prefix + ..., value)
calls that returned beforeSync(prefix)
was called will be observed afterSync(prefix)
returns, even if the program crashes.
- Insert calls to
Sync
where appropriate (in go-ipfs and go-libp2p). - When ready, turn off sync writes in go-ipfs's datastore (by default). (we'll have an experimental transition with heavy testing)
Notes:
- We're not changing the default behavior. Datastores will still write synchronously unless configured not to do so.
- Put will either completely put a value or not put a value. Even when sync writes is turned off, the datastore will never be left in a corrupt state.
Motivation
Writing to disk synchronously has poor performance and is rarely necessary.
Poor performance: ipfs add
performance is doubled (on linux/ext4) when badger is used and synchronous writes are turned off.
Rarely necessary:
- The DHT expects some number of nodes to be faulty so losing a few records is usually fine.
- IPFS only guarantees that blocks are persisted when pinned. There's no reason to sync after every write.
- Note: For now, we'll likely want to explicitly
sync
after a fullipfs add
as most users have GC turned off and expect the data to be persisted anyways. However, doing this once is cheaper than doing it for every write.
- Note: For now, we'll likely want to explicitly
- The peerstore definitely doesn't need synchronous writes.
Alternatives
- Create a buffered/batching/async wrapper. This is what go-ipfs currently does but we could do better.
- Use the "autobatching" datastore.
However:
- Buffering/caching isn't easy.
- Unlike buffering inside the OS, they can't (easily) respond to memory pressure.
- Conversely, they force one to eagerly sync/flush periodically instead of as-needed. The OS knows when we have enough memory to keep writing into memory.
@Stebalien @whyrusleeping @raulk Seem like a reasonable plan?
Metadata
Metadata
Assignees
Labels
No labels