Struct timely::worker::Worker

source ·
pub struct Worker<A: Allocate> { /* private fields */ }
Expand description

A Worker is the entry point to a timely dataflow computation. It wraps a Allocate, and has a list of dataflows that it manages.

Implementations§

source§

impl<A: Allocate> Worker<A>

source

pub fn new(config: Config, c: A) -> Worker<A>

Allocates a new Worker bound to a channel allocator.

source

pub fn step(&mut self) -> bool

Performs one step of the computation.

A step gives each dataflow operator a chance to run, and is the main way to ensure that a computation proceeds.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    use timely::dataflow::operators::{ToStream, Inspect};

    worker.dataflow::<usize,_,_>(|scope| {
        (0 .. 10)
            .to_stream(scope)
            .inspect(|x| println!("{:?}", x));
    });

    worker.step();
});
source

pub fn step_or_park(&mut self, duration: Option<Duration>) -> bool

Performs one step of the computation.

A step gives each dataflow operator a chance to run, and is the main way to ensure that a computation proceeds.

This method takes an optional timeout and may park the thread until there is work to perform or until this timeout expires. A value of None allows the worker to park indefinitely, whereas a value of Some(Duration::new(0, 0)) will return without parking the thread.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    use std::time::Duration;
    use timely::dataflow::operators::{ToStream, Inspect};

    worker.dataflow::<usize,_,_>(|scope| {
        (0 .. 10)
            .to_stream(scope)
            .inspect(|x| println!("{:?}", x));
    });

    worker.step_or_park(Some(Duration::from_secs(1)));
});
source

pub fn step_while<F: FnMut() -> bool>(&mut self, func: F)

Calls self.step() as long as func evaluates to true.

This method will continually execute even if there is not work for the worker to perform. Consider using the similar method Self::step_or_park_while(duration) to allow the worker to yield control if that is appropriate.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    use timely::dataflow::operators::{ToStream, Inspect, Probe};

    let probe =
    worker.dataflow::<usize,_,_>(|scope| {
        (0 .. 10)
            .to_stream(scope)
            .inspect(|x| println!("{:?}", x))
            .probe()
    });

    worker.step_while(|| probe.less_than(&0));
});
source

pub fn step_or_park_while<F: FnMut() -> bool>( &mut self, duration: Option<Duration>, func: F )

Calls self.step_or_park(duration) as long as func evaluates to true.

This method may yield whenever there is no work to perform, as performed by Self::step_or_park(). Please consult the documentation for further information about that method and its behavior. In particular, the method can park the worker indefinitely, if no new work re-awakens the worker.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    use timely::dataflow::operators::{ToStream, Inspect, Probe};

    let probe =
    worker.dataflow::<usize,_,_>(|scope| {
        (0 .. 10)
            .to_stream(scope)
            .inspect(|x| println!("{:?}", x))
            .probe()
    });

    worker.step_or_park_while(None, || probe.less_than(&0));
});
source

pub fn index(&self) -> usize

The index of the worker out of its peers.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    let index = worker.index();
    let peers = worker.peers();
    let timer = worker.timer();

    println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);

});
source

pub fn peers(&self) -> usize

The total number of peer workers.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    let index = worker.index();
    let peers = worker.peers();
    let timer = worker.timer();

    println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);

});
source

pub fn timer(&self) -> Instant

A timer started at the initiation of the timely computation.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    let index = worker.index();
    let peers = worker.peers();
    let timer = worker.timer();

    println!("{:?}\tWorker {} of {}", timer.elapsed(), index, peers);

});
source

pub fn new_identifier(&mut self) -> usize

Allocate a new worker-unique identifier.

This method is public, though it is not expected to be widely used outside of the timely dataflow system.

source

pub fn log_register(&self) -> RefMut<'_, Registry<WorkerIdentifier>>

Access to named loggers.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    worker.log_register()
          .insert::<timely::logging::TimelyEvent,_>("timely", |time, data|
              println!("{:?}\t{:?}", time, data)
          );
});
source

pub fn dataflow<T, R, F>(&mut self, func: F) -> R
where T: Refines<()>, F: FnOnce(&mut Child<'_, Self, T>) -> R,

Construct a new dataflow.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    // We must supply the timestamp type here, although
    // it would generally be determined by type inference.
    worker.dataflow::<usize,_,_>(|scope| {

        // uses of `scope` to build dataflow

    });
});
source

pub fn dataflow_named<T, R, F>(&mut self, name: &str, func: F) -> R
where T: Refines<()>, F: FnOnce(&mut Child<'_, Self, T>) -> R,

Construct a new dataflow with a (purely cosmetic) name.

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    // We must supply the timestamp type here, although
    // it would generally be determined by type inference.
    worker.dataflow_named::<usize,_,_>("Some Dataflow", |scope| {

        // uses of `scope` to build dataflow

    });
});
source

pub fn dataflow_core<T, R, F, V>( &mut self, name: &str, logging: Option<TimelyLogger>, resources: V, func: F ) -> R
where T: Refines<()>, F: FnOnce(&mut V, &mut Child<'_, Self, T>) -> R, V: Any + 'static,

Construct a new dataflow with specific configurations.

This method constructs a new dataflow, using a name, logger, and additional resources specified as argument. The name is cosmetic, the logger is used to handle events generated by the dataflow, and the additional resources are kept alive for as long as the dataflow is alive (use case: shared library bindings).

§Examples
timely::execute_from_args(::std::env::args(), |worker| {

    // We must supply the timestamp type here, although
    // it would generally be determined by type inference.
    worker.dataflow_core::<usize,_,_,_>(
        "dataflow X",           // Dataflow name
        None,                   // Optional logger
        37,                     // Any resources
        |resources, scope| {    // Closure

            // uses of `resources`, `scope`to build dataflow

        }
    );
});
source

pub fn drop_dataflow(&mut self, dataflow_identifier: usize)

Drops an identified dataflow.

This method removes the identified dataflow, which will no longer be scheduled. Various other resources will be cleaned up, though the method is currently in public beta rather than expected to work. Please report all crashes and unmet expectations!

source

pub fn next_dataflow_index(&self) -> usize

Returns the next index to be used for dataflow construction.

This identifier will appear in the address of contained operators, and can be used to drop the dataflow using self.drop_dataflow().

source

pub fn installed_dataflows(&self) -> Vec<usize>

List the current dataflow indices.

source

pub fn has_dataflows(&self) -> bool

True if there is at least one dataflow under management.

Trait Implementations§

source§

impl<A: Allocate> AsWorker for Worker<A>

source§

fn config(&self) -> &Config

Returns the worker configuration parameters.
source§

fn index(&self) -> usize

Index of the worker among its peers.
source§

fn peers(&self) -> usize

Number of peer workers.
source§

fn allocate<D: Data>( &mut self, identifier: usize, address: &[usize] ) -> (Vec<Box<dyn Push<Message<D>>>>, Box<dyn Pull<Message<D>>>)

Allocates a new channel from a supplied identifier and address. Read more
source§

fn pipeline<T: 'static>( &mut self, identifier: usize, address: &[usize] ) -> (ThreadPusher<Message<T>>, ThreadPuller<Message<T>>)

Constructs a pipeline channel from the worker to itself. Read more
source§

fn new_identifier(&mut self) -> usize

Allocates a new worker-unique identifier.
source§

fn log_register(&self) -> RefMut<'_, Registry<WorkerIdentifier>>

Provides access to named logging streams.
source§

fn logging(&self) -> Option<TimelyLogger>

Provides access to the timely logging stream.
source§

impl<A: Allocate> Clone for Worker<A>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<A: Allocate> Scheduler for Worker<A>

source§

fn activations(&self) -> Rc<RefCell<Activations>>

Provides a shared handle to the activation scheduler.
source§

fn activator_for(&self, path: &[usize]) -> Activator

Constructs an Activator tied to the specified operator address.
source§

fn sync_activator_for(&self, path: &[usize]) -> SyncActivator

Constructs a SyncActivator tied to the specified operator address.
source§

impl<A: Allocate> ScopeParent for Worker<A>

§

type Timestamp = ()

The timestamp associated with data in this scope.

Auto Trait Implementations§

§

impl<A> Freeze for Worker<A>

§

impl<A> !RefUnwindSafe for Worker<A>

§

impl<A> !Send for Worker<A>

§

impl<A> !Sync for Worker<A>

§

impl<A> Unpin for Worker<A>

§

impl<A> !UnwindSafe for Worker<A>

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<R, O, T> CopyOnto<ConsecutiveOffsetPairs<R, O>> for T
where R: Region<Index = (usize, usize)>, O: OffsetContainer<usize>, T: CopyOnto<R>,

source§

fn copy_onto( self, target: &mut ConsecutiveOffsetPairs<R, O> ) -> <ConsecutiveOffsetPairs<R, O> as Region>::Index

Copy self into the target container, returning an index that allows to look up the corresponding read item.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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<R, T> PushInto<FlatStack<R>> for T
where R: Region + Clone + 'static, T: CopyOnto<R>,

source§

fn push_into(self, target: &mut FlatStack<R>)

Push self into the target container.
source§

impl<T> PushInto<Vec<T>> for T

source§

fn push_into(self, target: &mut Vec<T>)

Push self into the target container.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

impl<T> Data for T
where T: Clone + 'static,