Skip to main content

DistributedRunner

Struct DistributedRunner 

Source
pub struct DistributedRunner { /* private fields */ }
Expand description

Orchestrates distributed tick execution.

The DistributedRunner coordinates tick execution across multiple shards, ensuring proper phase synchronization via barriers. Each tick consists of four phases (Sense, Act, Decay, Advance) that are executed in order across all shards before moving to the next phase.

§Architecture

The runner uses a coordinator for global synchronization and maintains references to all shard instances. During each tick:

  1. Sense Phase: All shards prepare agent decisions (read-only)
  2. Act Phase: All shards execute agent actions (write operations)
  3. Decay Phase: All shards decay signals, traces, and edges
  4. Advance Phase: Coordinator advances the global tick counter

After the Act phase, any cross-shard edges are collected and ghost nodes are resolved if configured.

§Example

use phago_distributed::runner::{DistributedRunner, RunnerConfig};

let runner = DistributedRunner::new(coordinator, shards, RunnerConfig::default());

// Run a single tick
let result = runner.tick().await?;
println!("Completed tick {}", result.tick);

// Run multiple ticks
let results = runner.run(10).await?;

Implementations§

Source§

impl DistributedRunner

Source

pub fn new( coordinator: Arc<Coordinator>, shards: Vec<Arc<RwLock<ShardedColony>>>, config: RunnerConfig, ) -> Self

Create a new distributed runner.

§Arguments
  • coordinator - The coordinator for global synchronization
  • shards - Vector of shard instances wrapped in Arc<RwLock<_>>
  • config - Runner configuration
Source

pub async fn tick(&self) -> DistributedResult<DistributedTickResult>

Run a single distributed tick.

Executes all four phases (Sense, Act, Decay, Advance) with barrier synchronization between each phase.

§Returns

A DistributedTickResult containing the new tick number, phase results, and any cross-shard edges that were created.

§Errors

Returns a DistributedError if:

  • Phase synchronization times out
  • Cross-shard edge resolution fails
Source

pub async fn run( &self, num_ticks: u64, ) -> DistributedResult<Vec<DistributedTickResult>>

Run multiple ticks.

§Arguments
  • num_ticks - Number of ticks to execute
§Returns

A vector of DistributedTickResult for each tick executed.

Source

pub fn coordinator(&self) -> &Arc<Coordinator>

Get the coordinator.

Source

pub fn shard_count(&self) -> usize

Get shard count.

Source

pub fn shards(&self) -> &[Arc<RwLock<ShardedColony>>]

Get a reference to all shards.

Source

pub fn config(&self) -> &RunnerConfig

Get runner configuration.

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.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

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

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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