Add a `PUSH` flag to signal partial input
When an object is longer than the buffer size (minus command overhead), Sonic is forced to do multiple writes to the KV store.
| Current | Desired |
|---|---|
|
|
The experimental flag NEW was recently introduced to avoid database reads altogether and let Sonic assume the object is new (acting as a “put” rather than a true “push”), but it’s not sufficient.
Indeed, Sonic is still forced to use merge operations in all follow-up requests, moving a ton of work to RocksDB which is our main ingestion bottleneck. Even worse, both RocksDB and the FST loose useful info like “this list is already uniqued” so they end up doing useless work.
Benefits (non-exhaustive)
PUSHoperations would calladd_term_to_iidsless often (~>“number of chunks per requests” times less).- This is a big thing, because
add_term_to_iidsis what’s causing probably 90% of the load on RocksDB, we already see a 2× speedup when commenting it out.
- This is a big thing, because
- During a batch ingestion, we wouldn’t call
add_iid_to_termsa single time anymore, removing even more load from RocksDB during merge.- This is also a nice win, because
add_iid_to_termsis probably all of the remaining load RocksDB has during merge (IIDIncris negligible).
- This is also a nice win, because
- When storing originals, Sonic could keep a whole document in memory and write once rather than relying on RocksDB merge operations to concatenate slices (which would be inefficient and add load to RocksDB… while we’re trying to offload it).
- Instead of writing $n$ unique sets of words to the FST, we could write only once so the FST would spend less time deduplicating values (time during which it is locked).
Flag name
I don’t know… PARTIAL? INCOMPLETE? MULTIPART? INTERMEDIATE? CHUNK? ... (literally)?
It would be experimental anyway so we don’t have to put too much thought into the name.
Compatibility
- A
PUSHwithout this flag would still behave the same. - A batch
PUSHwould be finalized by omitting said flag. Simple as that.- If a normal
PUSHis received AND there is pending data AND the previousPUSHwas for the same OID (Sonic already tracks that, see #405), then the full document is committed. If OIDs differ, a warning is logged, pending data is dropped and thePUSHrequest is processed as usual.
- If a normal
Subsequent propositions
- If we go down this road, I suggest we add a
CAPACITY(<usize>)(experimental) flag toPUSHso Sonic can reserve the correct amount of capacity to store the whole document, instead of re-allocating on everyPUSH. This flag would have to be passed on the first call only, and ignored on subsequent ones.- Since it’s closely tied to the flag I’m proposing in this issue, this capacity could be passed as an argument of it (
WHATEVER(<usize>)). However, it would either make the flag polymorphic (if we support not specifying the capacity) or waste bytes (+ make parsing harder) if we set it every time. For that reason, I suggest we use a separate flag.
- Since it’s closely tied to the flag I’m proposing in this issue, this capacity could be passed as an argument of it (
Source: valeriansaliou/sonic