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

vortex-data / vortex / 16600146115

29 Jul 2025 03:12PM UTC coverage: 82.699% (-0.006%) from 82.705%
16600146115

push

github

web-flow
fix: benchmark compress hang (#4051)

Signed-off-by: Alexander Droste <alexander.droste@protonmail.com>

0 of 10 new or added lines in 1 file covered. (0.0%)

3 existing lines in 1 file now uncovered.

45223 of 54684 relevant lines covered (82.7%)

184610.72 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 std::iter;
5
use std::sync::{Arc, LazyLock};
6

7
use futures::executor::block_on;
8
use futures::{StreamExt, stream};
9
use tokio::runtime::{Builder, Runtime};
10
use vortex_array::ArrayRef;
11
use vortex_array::iter::{ArrayIterator, ArrayIteratorAdapter};
12
use vortex_error::{VortexExpect, VortexResult, vortex_err};
13

14
use crate::ScanBuilder;
15

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

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

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

53
        let tasks = self.build()?;
×
54
        // We need to clone and send the map_fn into each task.
UNCOV
55
        let map_fn = Arc::new(map_fn);
×
UNCOV
56
        let handle = CPU_RUNTIME.handle().clone();
×
57

58
        let mut stream = stream::iter(tasks)
×
59
            .map(move |task| {
×
60
                let map_fn = map_fn.clone();
×
61
                // We don't _need_ to spawn the work here. But it allows Tokio to make progress on
62
                // the tasks in the background, even if the consumer thread is not calling
63
                // poll_next.
64

65
                handle.spawn(async move { task.await.transpose().map(|t| map_fn(t)) })
×
66
            })
×
67
            // TODO(ngates): this is very crude indeed. This buffered call essentially controls how
68
            //  many splits we have in-flight at any given time. We multiple workers by concurrency
69
            //  to configure per-thread concurrency, which essentially means each thread can make
70
            //  progress on one split while waiting for the I/O of another split to complete.
71
            //  In an ideal world, the number of in-flight tasks would be dynamically adjusted
72
            //  based on how much I/O the tasks _actually_ require. For example, all pruning tasks
73
            //  could be spawned immediately since they all use a single segment, this would allow
74
            //  head-room to run ahead and figure out the I/O demands of subsequent tasks.
75
            .buffered(num_workers * concurrency);
×
76

NEW
77
        Ok(iter::from_fn(move || {
×
78
            // Use runtime-aware blocking strategy
NEW
79
            if tokio::runtime::Handle::try_current().is_ok() {
×
NEW
80
                tokio::task::block_in_place(|| CPU_RUNTIME.handle().block_on(stream.next()))
×
81
            } else {
NEW
82
                block_on(stream.next())
×
83
            }
NEW
84
        })
×
NEW
85
        .filter_map(|result| {
×
NEW
86
            result
×
NEW
87
                .map_err(|e| vortex_err!("Failed to join on a spawned scan task {e}"))
×
NEW
88
                .vortex_expect("Failed to join on a spawned scan task")
×
NEW
89
        }))
×
UNCOV
90
    }
×
91
}
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