Struct renoir::StreamContext

source ·
pub struct StreamContext { /* private fields */ }
Expand description

Streaming environment from which it’s possible to register new streams and start the computation.

This is the entrypoint for the library: construct an environment providing an RuntimeConfig, then you can ask new streams providing the source from where to read from.

If you want to use a distributed environment (i.e. using remote workers) you have to spawn them using spawn_remote_workers before asking for some stream.

When all the stream have been registered you have to call execute that will consume the environment and start the computation. This function will return when the computation ends.

TODO: example usage

Implementations§

source§

impl StreamContext

source

pub fn new(config: RuntimeConfig) -> Self

Construct a new environment from the config.

source

pub fn new_local() -> Self

source

pub fn stream<S>(&self, source: S) -> Stream<S>
where S: Source + Send + 'static,

Construct a new stream bound to this environment starting with the specified source.

source

pub fn execute_blocking(self)

Start the computation. Blocks until the computation is complete.

Execute on a thread or use the async version [execute] for non-blocking alternatives

source

pub fn parallelism(&self) -> CoordUInt

Get the total number of processing cores in the cluster.

source§

impl StreamContext

source

pub fn stream_csv<T: Data + for<'a> Deserialize<'a>>( &self, path: impl Into<PathBuf> ) -> Stream<CsvSource<T>>

Convenience method, creates a CsvSource and makes a stream using StreamContext::stream

source§

impl StreamContext

source

pub fn stream_file<P: Into<PathBuf>>(&self, path: P) -> Stream<FileSource>

Convenience method, creates a FileSource and makes a stream using StreamContext::stream

source§

impl StreamContext

source

pub fn stream_iter<It>(&self, iterator: It) -> Stream<IteratorSource<It>>
where It: Iterator + Send + 'static, It::Item: Send,

Convenience method, creates a IteratorSource and makes a stream using StreamContext::stream

source§

impl StreamContext

source

pub fn stream_par_iter<Source>( &self, generator: Source ) -> Stream<ParallelIteratorSource<Source>>
where Source: IntoParallelSource + 'static, Source::Iter: Send, <Source::Iter as Iterator>::Item: Send,

Convenience method, creates a ParallelIteratorSource and makes a stream using StreamContext::stream

§Example:
use renoir::prelude::*;

let env = StreamContext::new_local();

env.stream_par_iter(0..10)
    .for_each(|q| println!("a: {q}"));

let n = 10;
env.stream_par_iter(
    move |id, instances| {
        let chunk_size = (n + instances - 1) / instances;
        let remaining = n - n.min(chunk_size * id);
        let range = remaining.min(chunk_size);
         
        let start = id * chunk_size;
        let stop = id * chunk_size + range;
        start..stop
    })
   .for_each(|q| println!("b: {q}"));

env.execute_blocking();

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more