Skip to content

Commit 8a45494

Browse files
docs(Echo): update architectural documentation and usage examples
- Align README.md crate references from `echo-scheduler` to `Echo` for consistency with internal naming - Refine module structure documentation to reflect final synthesized architecture separation between generic `Queue` and application-specific `Scheduler`/`Task` - Update code samples to match actual implementation patterns (e.g., `Builder::Create()` vs `New()`) - Enhance Deep Dive explanations of work-stealing mechanics and context ownership model - Clarify Mountain integration workflow showing `ActionEffect` execution through Echo's scheduler These changes ensure documentation accuracy for the core concurrency system that drives Mountain's `ActionEffect` processing and Cocoon's extension host operations.
1 parent ccdd32d commit 8a45494

2 files changed

Lines changed: 165 additions & 143 deletions

File tree

README.md

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# **Echo** 📣 A Resilient, High-Performance Task Scheduler for Rust
1313

1414
[![License: CC0-1.0](https://img.shields.io/badge/License-CC0_1.0-lightgrey.svg)](https://github.com/CodeEditorLand/Echo/tree/Current/LICENSE)
15-
[![Crates.io](https://img.shields.io/crates/v/echo-scheduler.svg)](https://crates.io/crates/echo-scheduler)
15+
[![Crates.io](https://img.shields.io/crates/v/Echo.svg)](https://crates.io/crates/Echo)
1616
[![Tokio Version](https://img.shields.io/badge/Tokio-v1-blue.svg)](https://tokio.rs/)
1717
[![Crossbeam Version](https://img.shields.io/badge/Crossbeam-v0.8-blueviolet.svg)](https://github.com/crossbeam-rs/crossbeam)
1818

@@ -47,11 +47,10 @@ executing complex asynchronous workflows with resilience and efficiency.
4747
- **Task Prioritization:** Supports submitting tasks with `High`, `Normal`, or
4848
`Low` priority, ensuring that latency-sensitive operations are handled
4949
immediately.
50-
- **Fluent Builder API:** A clean `SchedulerBuilder` allows for easy
51-
configuration of the worker pool and other scheduler parameters.
52-
- **Graceful Shutdown:** Provides a `Shutdown()` method to ensure all worker
53-
threads complete their current tasks and exit cleanly, preventing orphaned
54-
threads.
50+
- **Fluent Builder API:** A clean `Builder` allows for easy configuration of the
51+
worker pool and other scheduler parameters.
52+
- **Graceful Shutdown:** Provides a `Stop()` method to ensure all worker threads
53+
complete their current tasks and exit cleanly, preventing orphaned threads.
5554
- **Built for `ActionEffect`:** Serves as the ideal backend for effect systems,
5655
providing the runtime engine that executes declarative, asynchronous workflows
5756
defined in other parts of the application.
@@ -60,13 +59,13 @@ executing complex asynchronous workflows with resilience and efficiency.
6059

6160
## Core Architecture Principles 🏗️
6261

63-
| Principle | Description | Key Components Involved |
64-
| :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------ |
65-
| **Performance** | Use lock-free data structures (`crossbeam-deque`) and a work-stealing algorithm to achieve maximum throughput and low-latency task execution. | `queue::StealingQueue`, `scheduler::Worker` |
66-
| **Structured Concurrency** | Manage all asynchronous operations within a supervised pool of workers, providing graceful startup and shutdown, unlike fire-and-forget `tokio::spawn`. | `scheduler::Scheduler`, `SchedulerBuilder` |
67-
| **Decoupling** | Separate the _submission_ of a task from its _execution_. The `AppRuntime` submits work, and the `Scheduler` handles how, when, and where it runs. | `Scheduler::Submit`, `task::Task` |
68-
| **Resilience** | The scheduler's design is inherently resilient, as the failure of one task (if it panics) does not bring down the entire worker pool. | `scheduler::Worker` (execution loop) |
69-
| **Composability** | Provide a simple, generic `Submit` API that accepts any `Future<Output = ()>`, making it easy to integrate with any asynchronous Rust code. | `task::Task`, `Scheduler::Submit` |
62+
| Principle | Description | Key Components Involved |
63+
| :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------ | :---------------------------------------------------- |
64+
| **Performance** | Use lock-free data structures (`crossbeam-deque`) and a work-stealing algorithm to achieve maximum throughput and low-latency task execution. | `Queue::StealingQueue`, `Scheduler::Worker` |
65+
| **Structured Concurrency** | Manage all asynchronous operations within a supervised pool of workers, providing graceful startup and shutdown, unlike fire-and-forget `tokio::spawn`. | `Scheduler::Scheduler`, `Scheduler::SchedulerBuilder` |
66+
| **Decoupling** | Separate the _submission_ of a task from its _execution_. The application submits work, and the `Scheduler` handles how, when, and where it runs. | `Scheduler::Scheduler::Submit`, `Task::Task::Task` |
67+
| **Resilience** | The scheduler's design is inherently resilient, as the failure of one task (if it panics) does not bring down the entire worker pool. | `Scheduler::Worker::Run` (execution loop) |
68+
| **Composability** | Provide a simple, generic `Submit` API that accepts any `Future<Output = ()>`, making it easy to integrate with any asynchronous Rust code. | `Task::Task::Task`, `Scheduler::Scheduler::Submit` |
7069

7170
---
7271

@@ -91,7 +90,6 @@ graph LR
9190
classDef echo fill:#ffc,stroke:#333,stroke-width:2px;
9291
classDef rust fill:#f9d,stroke:#333,stroke-width:1px;
9392
94-
9593
subgraph "Common (Abstract Core)"
9694
ActionEffect["ActionEffect (Task Definition)"]:::common
9795
end
@@ -127,10 +125,10 @@ The `Echo` repository is organized into a few core modules:
127125
```
128126
Echo/
129127
└── Source/
130-
├── lib.rs # Crate root, declares public modules.
131-
├── scheduler/ # The main public API: Scheduler and SchedulerBuilder.
132-
├── queue/ # The internal, high-performance work-stealing queue.
133-
└── task/ # The internal definition of a Task and its Priority.
128+
├── Library.rs # Crate root, declares all modules.
129+
├── Scheduler/ # The main public API: Scheduler and Builder.
130+
├── Queue/ # The generic, high-performance work-stealing queue.
131+
└── Task/ # The application-specific definition of a Task and its Priority.
134132
```
135133

136134
---
@@ -139,64 +137,71 @@ Echo/
139137

140138
### Installation
141139

142-
```sh
143-
# In your Cargo.toml
140+
To add `Echo` to your project, add the following to your `Cargo.toml`:
141+
142+
```toml
144143
[dependencies]
145-
echo-scheduler = "0.1.0" # Or use a path dependency for local development
144+
Echo = { git = "https://github.com/CodeEditorLand/Echo.git", branch = "Current" }
146145
```
147146

148147
**Key Dependencies:**
149148

150-
- `tokio`: `^1.0` (with `full` features)
151-
- `crossbeam-deque`: `^0.8`
152-
- `rand`: `^0.8`
153-
- `log`: `^0.4`
149+
- `tokio = { version = "1", features = ["full"] }`
150+
- `crossbeam-deque = "0.8"`
151+
- `rand = "0.8"`
152+
- `log = "0.4"`
153+
- `num_cpus = "1.0"`
154154

155155
### Usage
156156

157157
`Echo` is designed to be integrated into an application's main entry point and
158-
used via a shared `AppRuntime`.
158+
used throughout the application, often via a shared context or runtime.
159159

160-
1. **Initialize the Scheduler:** Create and start the scheduler when your
161-
application starts.
160+
1. **Define the Public API:** In your library's root (`lib.rs` or `main.rs`),
161+
re-export the primary components for easy access.
162162

163163
```rust
164-
// In your application's main.rs
165-
use Echo::scheduler::{Scheduler, SchedulerBuilder};
166-
use std::sync::Arc;
167-
168-
let scheduler = Arc::new(SchedulerBuilder::New().WithWorkerCount(8).Build());
164+
// In your application's lib.rs
165+
pub use Echo::Scheduler::{Scheduler, SchedulerBuilder as Builder, Priority};
169166
```
170167

171-
2. **Create a Runtime:** Construct a runtime object that holds the scheduler
172-
and any other necessary context (like your application's `Environment`).
168+
2. **Initialize the Scheduler:** Create and start the scheduler when your
169+
application starts. It is typically wrapped in an `Arc` to be shared safely
170+
across your application.
173171

174172
```rust
175-
use Common::effect::AppRuntime as AppRuntimeTrait;
176-
177-
struct MyAppRuntime {
178-
scheduler: Arc<Scheduler>,
179-
// ... other context
180-
}
173+
// In your application's main function
174+
use std::sync::Arc;
181175

182-
// This runtime will submit tasks to the scheduler.
183-
// (See the full implementation from our synthesis session for details).
176+
// Use the fluent builder to configure and build the scheduler
177+
let Scheduler = Arc::new(Builder::Create().Count(8).Build());
184178
```
185179

186-
3. **Submit Tasks:** Use your runtime to submit asynchronous work to the
187-
scheduler.
180+
3. **Submit Tasks:** Use the `Scheduler` instance to submit asynchronous work
181+
from anywhere in your application.
188182

189183
```rust
190-
use Echo::task::Priority;
191-
192184
// An example async block to be run by the scheduler
193-
let my_task = async {
194-
println!("This is running on a worker thread!");
185+
let MyTask = async {
186+
println!("This is running on an Echo worker thread!");
195187
// ... perform some work ...
196188
};
197189

198-
// The runtime's `Run` method would internally call this:
199-
runtime.scheduler.Submit(my_task, Priority::Normal);
190+
// Submit the task with a desired priority
191+
Scheduler.Submit(MyTask, Priority::Normal);
192+
193+
// Another example with high priority
194+
Scheduler.Submit(async { /* critical work */ }, Priority::High);
195+
```
196+
197+
4. **Graceful Shutdown:** Before your application exits, ensure a clean
198+
shutdown of all worker threads.
199+
200+
```rust
201+
// In your application's shutdown sequence
202+
if let Some(mut Scheduler) = Arc::get_mut(&mut Scheduler) {
203+
Scheduler.Stop().await;
204+
}
200205
```
201206

202207
---

0 commit comments

Comments
 (0)