• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16498604695

24 Jul 2025 01:43PM UTC coverage: 81.131% (+0.04%) from 81.087%
16498604695

Pull #4005

github

web-flow
Merge 45a44d9de into f25ddb6bf
Pull Request #4005: Remove scan async API

146 of 215 new or added lines in 10 files covered. (67.91%)

7 existing lines in 2 files now uncovered.

42206 of 52022 relevant lines covered (81.13%)

173170.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/vortex-scan/src/multi_thread.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use crate::ScanBuilder;
5
use futures::executor::block_on;
6
use futures::{StreamExt, stream};
7
use std::iter;
8
use std::sync::{Arc, LazyLock};
9
use tokio::runtime::{Builder, Runtime};
10
use vortex_array::ArrayRef;
11
use vortex_array::iter::{ArrayIterator, ArrayIteratorAdapter};
12
use vortex_error::{VortexExpect, VortexResult};
13

14
/// We create an internal Tokio runtime used exclusively for orchestrating work-stealing
15
/// of CPU-bound work for multithreaded scans.
16
///
17
/// It is intentionally not exposed to the user, not configurable, and does not enable I/O or
18
/// timers.
NEW
19
static CPU_RUNTIME: LazyLock<Runtime> = LazyLock::new(|| {
×
NEW
20
    Builder::new_multi_thread()
×
NEW
21
        .thread_name("vortex-multithread-scan")
×
NEW
22
        .build()
×
NEW
23
        .vortex_expect("Failed to create a new Tokio runtime")
×
NEW
24
});
×
25

26
impl ScanBuilder<ArrayRef> {
27
    /// Execute the scan on multiple worker threads.
NEW
28
    pub fn into_array_iter_multithread(self) -> VortexResult<impl ArrayIterator + Send + 'static> {
×
NEW
29
        let dtype = self.dtype()?;
×
NEW
30
        Ok(ArrayIteratorAdapter::new(
×
NEW
31
            dtype,
×
NEW
32
            self.into_iter_multithread(|a| a)?,
×
33
        ))
NEW
34
    }
×
35

36
    /// Execute the scan on multiple worker threads.
37
    ///
38
    /// A `map_fn` can be passed to further transform the results of the scan while still running
39
    /// on the thread pool.
NEW
40
    pub fn into_iter_multithread<T, F>(
×
NEW
41
        self,
×
NEW
42
        map_fn: F,
×
NEW
43
    ) -> VortexResult<impl Iterator<Item = T> + Send + 'static>
×
NEW
44
    where
×
NEW
45
        T: 'static + Send,
×
NEW
46
        F: Fn(VortexResult<ArrayRef>) -> T + Send + Sync + 'static,
×
47
    {
NEW
48
        let concurrency = self.concurrency;
×
NEW
49
        let num_workers = CPU_RUNTIME.metrics().num_workers();
×
50

NEW
51
        let tasks = self.build()?;
×
52

53
        // We need to clone and send the map_fn into each task.
NEW
54
        let map_fn = Arc::new(map_fn);
×
55

NEW
56
        let handle = CPU_RUNTIME.handle().clone();
×
NEW
57
        let mut stream = stream::iter(tasks)
×
NEW
58
            .map(move |task| {
×
NEW
59
                let map_fn = map_fn.clone();
×
60
                // We don't _need_ to spawn the work here. But it allows Tokio to make progress on
61
                // the tasks in the background, even if the consumer thread is not calling
62
                // poll_next.
NEW
63
                handle.spawn(async move { task.await.transpose().map(|t| map_fn(t)) })
×
NEW
64
            })
×
65
            // TODO(ngates): this is very crude indeed. This buffered call essentially controls how
66
            //  many splits we have in-flight at any given time. We multiple workers by concurrency
67
            //  to configure per-thread concurrency, which essentially means each thread can make
68
            //  progress on one split while waiting for the I/O of another split to complete.
69
            //  In an ideal world, the number of in-flight tasks would be dynamically adjusted
70
            //  based on how much I/O the tasks _actually_ require. For example, all pruning tasks
71
            //  could be spawned immediately since they all use a single segment, this would allow
72
            //  head-room to run ahead and figure out the I/O demands of subsequent tasks.
NEW
73
            .buffered(num_workers * concurrency);
×
74

NEW
75
        Ok(iter::from_fn(move || block_on(stream.next()))
×
NEW
76
            .filter_map(|result| result.vortex_expect("Failed to join on a spawned scan task")))
×
NEW
77
    }
×
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc