https://slatedb.io logo
Hello folks,
# general
s
Hello folks, I was going through the scan_with_options() code. Can we parallelise the part of creating iterators for l0 ssts and srs rather than for looping and awaiting?
Copy code
rust
let mut l0_iters = VecDeque::new();
        for sst in &db_state.core().l0 {
            if let Some(iter) = SstIterator::new_owned(
                range.clone(),
                sst.clone(),
                self.table_store.clone(),
                sst_iter_options,
            )
            .await?
            {
                l0_iters.push_back(iter);
            }
        }

        let mut sr_iters = VecDeque::new();
        for sr in &db_state.core().compacted {
            let iter = SortedRunIterator::new_owned(
                range.clone(),
                sr.clone(),
                self.table_store.clone(),
                sst_iter_options,
            )
            .await?;
            sr_iters.push_back(iter);
        }
Something like combining all using an
.allOf
on all the collected CompletableFutures in java and then a
.get
. cc: @criccomini
c
I think creating the iterators is very cheap. IIRC, they manage block fetching asynchronously underneath, right?
spawn_fetches
So the actual reading is done async already
s
The
read_index
could call the object store in case there is a cache miss. Based on the current code logic, the calls to the object store might be serial( since we build iterators one by one). Parallelising the above code would also parallelise the fetch, right?
c
Oh interesting. Yes, you're right!
In that case, yea, parallelizing might be a good idea... I wonder if it makes sense to do it in the SstIterator vs. outside...
s
I think SstIterator logic would remain the same since we cannot do much there. I think it would be more method specific since single iterator fetch won't have this issue. This would optimise when we plan to build a vector of iterators. So, better to keep it outside so that each method can handle it based on it's query pattern.
c
SGTM
s
Could this also improve scan performance?
c
Yes
That's why I was wondering about generalizing it
scan+compactor
I think we might already create ssts in parallel in compactor right?
s
Ah..Now I get it. You mean to say have some layer between these method calls and SstIterator struct that handles this?
c
yea... it might be kinda ugly
s
> I think we might already create ssts in parallel in compactor right? I think this could also help with the iterator logic in compactor.
c
Yea
s
I can create a PR for this change. Should I create an issue?
c
Perhaps the best way to do this is to put the logic in
MergeIterator
Ya open up a GH issue
I think it requires a little thought about the best approach (to keep things clean).. would appreciate your thoughts there
s
r
@Pierre opened a PR that does basically this for the compactor: https://github.com/slatedb/slatedb/pull/784/files It's probably worth doing the l0s and srs concurrently, especially for scan which actually opens iterators for both
s
We need to discuss whether we need a central place to hold these changes or just improve the parts where the iterator creation in sequential
r
I don't feel terribly strongly one way or another. It would be nice if we could have a common interface for loading a part of the tree into iterators. At the same time the compactor and scan have specific wrappers over the iterators that makes this kind of challenging to bake into
MergeIterator
. Maybe just some helper fn that takes a list of sources and returns iterators is good enough
c
Yes I’m leaning towards a helper
s
@criccomini can you assign me the issue?
https://github.com/slatedb/slatedb/pull/815 Created my first SlateDb PR šŸ˜„ Can you take a look.
p
Not sure to get what's the difference with my own PR on that šŸ˜„
c
Sujeet's doesn't modify the
max_fetch_tasks
and
blocks_to_fetch
, which Rohan had been suspicious about. It also updates scan (not just compactor). And centralizes logic.
p
Could have been iterative improvement on mine as it's almost the exact same changes šŸ¤·ā€ā™‚ļø Not that I care much but it's hard to follow lol
I'll close mine then
c
ya I think you guys both realized it but for different parts of the code (scan vs compactor)
p
Yeah no worries, really not a big deal!
(And his PR is better in the end!)
s
Hello @Pierre As Chris mentioned, I found the sequential execution for the scan_with_options() and wasn't aware about a similar PR until Rohan added it later to the thread. I can close my PR if you want to take this forward.
Just saw, you have closed your PR. Thanks! I will take it forward.
Can I get a review on the above PR
c
yessir... you are moving much faster than I am right now--lots going on šŸ˜