https://slatedb.io logo
OK I ran benchmarks from HEAD and compared to righ...
# general
a
OK I ran benchmarks from HEAD and compared to right before merging #325 which would be the regression. It's definitely a little worse, but not nearly as significant as the microbenchmarks suggest. Creating a thread with some of the results.
Baseline 60_4:
HEAD 60_4:
Baseline 20_4:
HEAD 20_4:
There's no perceptible regression in the
100_1
or
100_4
categories, which doesn't totally make sense to me
I guess going from <1us to ~6us doesn't make much of a difference when you can only do ~5K ops/s/thread anyway (~200us/op). It's about a 2.5% degredation overall.
d
Why are we limited to 5k op/s?
I need to get to somewhere between 100k-1M/s for it to be a feasible replacement for RocksDB
a
Note that that's per thread on my laptop, but as far as the actual limitations I'm not sure - I haven't done much of analysis on where the bottlnecks are
and puts/s, not ops/s (my bad)
d
šŸ‘ I'll try to run some more experiments when I have capacity
oh, maybe are you running with WriteOptions(durable=true)?
a
I'm running with the default in the bencher, which I think is with await_durable=false and no WAL
Copy code
target/release/bencher --path /slatedb-bencher_100_4 db --db-options-path /Users/agavra/dev/slatedb/src/bencher/Slatedb.toml --duration 60 --val-len 8192 --block-cache-size 134217728 --put-percentage 100 --concurrency 4
(replacing put-percentage and concurrency where applicable)
value lengths are also 8k, which is more than in the microbench
Yeah, here's a run with 60_4 and 192 byte values:
Closer to 200K puts/s (and 300k ops/s) though it degrades quickly as we start hitting disk, which makes sense
let me run that against HEAD as well to see the extent of regression with smaller values
Even then the regression isn't very pronounced. I wonder why
cc @criccomini since you're playing around with perf you might find this discussion interesting. I wonder if we can enhance microbenchmarks to test different paths (i.e. memtable write, memtable flush, etc...)
c
I bet we could.. might require some back bending, tho..
Also, I wonder if the discrepency here is because we're using InMemory in the microbenchmark and local FS for bencher.
When using inmemory, we're effectively testing the CPU speed..
So very small issues could get exposed.
But compared to disk writes, it's negligible.
a
Ah, might be worth me re-running that experiment with in-memory and seeing if the degradation is as pronounced
Though await_durable=false and enable_wal=false in the bencher by default, right?
c
Yea-- just careful. The reason I didn't use in memory for
bencher
is because the data size is large. It very quickly explodes the memory usage.
await_durable for sure.. enable_wal, I don't recall
a
yeah just confirmed wal_enabled=false
d
I went down the rabbit hole and started playing with the bencher. Now I'm getting higher throughput when I enable WAL for the following setup. 🤣 How is that even possible, it has more work to do šŸ™ˆ Roughly 300k/s vs 360k/s https://gist.github.com/dmvk/23b0feb6c8ad051cd95e1d224f665846
I was wondering why increased bencher concurrency doesn't improve throughput all that much. It seems to boil down to having a mutext around WAL / Memtable in write_batch. Maybe that would be possible to avoid (for actaul write into map, not for metadata ops) , the SkipListMap itself is already thread safe -> it's actually designed to increase throughput when writing from multiple threads. šŸ¤”
With RWLock approach, is there actually any benefit from using SkipMap (it should be comparably slower to BTreeMap for example)?
c
Re: SkipMap, I cargo culted that from mini-lsm. But we've diverged so much...
The RWLock does indeed make all puts go through a single thread.. IIRC, my thinking was that we were going to serialize requests in order to get sequence numbers for txn's anyway /cc @flaneur233
Tho, perhaps those two things are orthogonal.. we could still have puts go through a single thread without a lock, I guess?
Will have to take a look at the code again..
Thinking on this more, I think we should be able to do it without a lock, like you said..
Probably worth a GH issue šŸ˜…
@flaneur233 you've dug into RocksDB more than I: do you know if they take a lock on the write path? I figure they must, but perhaps not for the skipmap?
But I still don't totally understand how they can handle a lockless write when two threads both write to the same key simultaneously. One must win...
f
i haven't learned the details here, but in my understanding if we need read memtable else where, we still need add a lock over it unless using a concurrency-safe data structure
c
So, SkipMap is concurrency safe.
But my question is mostly around writes..
Which is what @dmvk was talking about
@flaneur233 One thing I'm not clear on in #260 (the txn RFC) is how we're storing kv pairs in the memtable/kvtable once we add seqnum
If we start a txn, then we only want to see kv pairs up to that txn's seqnum. If a put overwrites a key with a new value (and a higher seqnum), we have to keep the old one around, right? IIRC, you mentioned storing a seqnum suffix in the key?
i still havent figured out the parallel write memtable here is to parallel ingest one BIG write batch into the memtable, or ingest multiple write batches concurrently into memtable 😯
the memtable should contain multiple versions of kv pairs, each kv pair is bound with a sequence number, i am planning to add this in https://github.com/slatedb/slatedb/issues/274 hopefully this weekend
yes, the old ones should still be kept,
c
How are they kept in the memtable? Using a seqnum suffix?
Ah, I see th VART comment now
(Would be helpful to have a note about this in the RFC as well, but no biggy)
f
this confuses me a bit, when we say concurrency, it's mostly called when we have concurrently write from different writers 😯
c
Hmm..
f
asked gpt4-o: If a thread is writing to the memtable, other threads can also write to it concurrently, as long as there is no direct conflict (e.g., two threads updating the same key). If there is contention (e.g., two threads operating on the same key, or during compaction-related operations), RocksDB may serialize the writes or fallback to single-threaded mode temporarily.
feel this explanation makes sence, if two writes do not conflicts on keys, it's not bad to have them both write concurrently 😯
i feel this not different a lot with a striding + 2pc when conflicts approach, like we can shard the memtable into 10 strides (or shards), and if you have two concurrent writes which overlapped on a same shard, you'd fallback to something like a 2pc or lock coordination 😯
it seems that rocksdb's write thread may help manage the order of writes. if it consumes some write batches (from the commit pipeline?) and found they do not have conflicts, it can run them in parallel.
on the other hand, if it consumes some write batches and found that they have key conflicts, it can simply fallback to using one thread
also, if it got a BIG write batch, it can also split it into smaller chunks and ingest them in parallel into memtable
c
This is why I was asking about our seqnum stuff in the memtable. I don't think we'll have this issue--there should never be a conflict.
That's very clever..
Makes sense
f
yeah, i found a RFC it's still needed, i'll draft one. (however i am afraid that i need some PoC over code first, the concept is simple, but need to put some trial & error to figure out how to add it into the code base 😬)
c
Yea, I think POC is fine.
I would really like to get the current txn RFC merged. I think it's pretty solid, modulo those couple of questions at the end.
So I'm fine with POC + merge the current RFC in parallel. Then subsequent RFC (or just docs) later.
f
yeah, it seems that the concurrency write feature in rocksdb is pretty self contained. all it need to do is to manage the write batches from commit pipeline, and do parallel writes as best effort, no other code need to be touched elsewhere.
c
@dmvk tl;dr on this very long conversation: I think we can support lockless memtable/kvtable writes. šŸ˜…
f
the difference between the single thread version of write is: the single thread writer consumes one write batch a time; the concurrency one consumes a batch of write batch a time 😯
c
Haha yea..
Was just writing: to mimic that, it seems maybe we could have the current
write_batch
act as a coordinator that could receive incoming `WriteBatch`es and shunt them off to a threadpool to write in parallel.
f
this approach is surprising clean
c
Yea, it reminds me of the actor model kinda
Need to think on this a bit.. our write path is a little different right now. We have the
maybe_freeze_wal
stuff that shifts a full WritableKVTable over to imm_wal and stuff
f
but writing to memtable should be atomic imho, it might have risks to simply
for (k, v) in kv_list { memtable.set(k, v) }
with skiplist is concurrent safe, while there's some one else reading the memtable without locking šŸ‘€, we should have some way to append a batch to the memtable atomicly
c
Yea.. not sure how to achieve that without a lock ..
Maybe prevent reads on seqnums >= the start of the batch write until the batch write completes?
f
i am afraid of the correctness will be harder to reason about if we do not assume the writes to the memtable is atomic 🄹
c
Or, force any batch write to trigger a new memtable..
f
it seems that rocksdb's skiplist is not thread safe, it still have a lock over it 😯
c
šŸ˜…
gotta put the kiddos to bed .. /me runs away
Seems like this will need some thought..
(and more investigation)
Worth a GH issue, tho
// Writes via Insert require external synchronization, most likely a mutex.
have a good night : )
d
it also means you need to keep old values around until read has completed (= more or less snapshot iteration)
I might be also misinterpreting the code ... still pretty new to rust.
Copy code
let snapshot = self.state.read().snapshot();
Is the read guard released when snapshot goes out of scope, or immediately? If immediately don't we already have a problem with underlying state being modified during read (there doesn't seem to be any real point-in-time snapshot of memtable for example)?
f
i think so, if it's a lock, the read lock is released after
snapshot()
returned 😯 (if
snapshot()
returns a reference not a value, the lock scope may last longer, but i guess the lifetime checker should not permit this...)
i personally prefer to explicitly use a block to scope the lock even it's a one-liner if linter allows
d
> but writing to memtable should be atomic imho, it might have risks to simply for (k, v) in kv_list { memtable.set(k, v) } with skiplist is concurrent safe, while there's some one else reading the memtable without locking so this should already be the case šŸ¤”
2 Views