2026-02-06 11:25:37 +00:00
|
|
|
use std::sync::Arc;
|
feat(myelin): add actor-backed job data plane and uploads
Replace the eventfd/ring job bootstrap with one inherited arena descriptor, actor-owned sessions, sealed blob leases, awaitable inbox wakeups, and zero-copy Python mappings. Route VastAI mock provisioning through image-backed local Docker workers and preserve pinned child and controller routes across directory updates.
Add TOML job-file submission to the Fleet UI with generic started, running, and completed feedback, reusable remote job controller routing, cancellation and kill invariants, Tinygrad fixture and image support, and comprehensive Rust, Python, CUDA, and lifecycle-ordering coverage.
2026-08-21 14:45:10 +00:00
|
|
|
use std::task::{Context, Poll};
|
2026-02-06 11:25:37 +00:00
|
|
|
|
feat(myelin): add actor-backed job data plane and uploads
Replace the eventfd/ring job bootstrap with one inherited arena descriptor, actor-owned sessions, sealed blob leases, awaitable inbox wakeups, and zero-copy Python mappings. Route VastAI mock provisioning through image-backed local Docker workers and preserve pinned child and controller routes across directory updates.
Add TOML job-file submission to the Fleet UI with generic started, running, and completed feedback, reusable remote job controller routing, cancellation and kill invariants, Tinygrad fixture and image support, and comprehensive Rust, Python, CUDA, and lifecycle-ordering coverage.
2026-08-21 14:45:10 +00:00
|
|
|
use atomic_waker::AtomicWaker;
|
2026-02-06 11:25:37 +00:00
|
|
|
use crossbeam_queue::{ArrayQueue, SegQueue};
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
|
|
|
|
|
pub struct HybridChannel<T> {
|
|
|
|
|
ring: ArrayQueue<T>,
|
2026-02-06 11:25:37 +00:00
|
|
|
overflow: SegQueue<T>,
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> HybridChannel<T> {
|
|
|
|
|
pub fn new(capacity: usize) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
ring: ArrayQueue::new(capacity),
|
2026-02-06 11:25:37 +00:00
|
|
|
overflow: SegQueue::new(),
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 07:35:58 +00:00
|
|
|
pub fn push(&self, value: T) {
|
2026-02-09 07:24:16 +00:00
|
|
|
if !self.overflow.is_empty() {
|
|
|
|
|
self.overflow.push(value);
|
2026-02-10 07:35:58 +00:00
|
|
|
return;
|
2026-02-09 07:24:16 +00:00
|
|
|
}
|
2026-02-10 07:35:58 +00:00
|
|
|
if let Err(v) = self.ring.push(value) {
|
|
|
|
|
self.overflow.push(v);
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn pop(&self) -> Option<T> {
|
2026-02-09 19:05:37 +00:00
|
|
|
self.ring.pop().or_else(|| self.overflow.pop())
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
}
|
2026-02-25 11:11:03 +00:00
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
|
self.ring.is_empty() && self.overflow.is_empty()
|
|
|
|
|
}
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
feat(myelin): add actor-backed job data plane and uploads
Replace the eventfd/ring job bootstrap with one inherited arena descriptor, actor-owned sessions, sealed blob leases, awaitable inbox wakeups, and zero-copy Python mappings. Route VastAI mock provisioning through image-backed local Docker workers and preserve pinned child and controller routes across directory updates.
Add TOML job-file submission to the Fleet UI with generic started, running, and completed feedback, reusable remote job controller routing, cancellation and kill invariants, Tinygrad fixture and image support, and comprehensive Rust, Python, CUDA, and lifecycle-ordering coverage.
2026-08-21 14:45:10 +00:00
|
|
|
struct AsyncInboxQueue<T> {
|
|
|
|
|
queue: HybridChannel<T>,
|
|
|
|
|
waker: AtomicWaker,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> AsyncInboxQueue<T> {
|
|
|
|
|
fn new(capacity: usize) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
queue: HybridChannel::new(capacity),
|
|
|
|
|
waker: AtomicWaker::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn push(&self, value: T) {
|
|
|
|
|
self.queue.push(value);
|
|
|
|
|
self.waker.wake();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn try_pop(&self) -> Option<T> {
|
|
|
|
|
self.queue.pop()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn poll_pop(&self, cx: &mut Context<'_>) -> Poll<T> {
|
|
|
|
|
if let Some(value) = self.try_pop() {
|
|
|
|
|
return Poll::Ready(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.waker.register(cx.waker());
|
|
|
|
|
|
|
|
|
|
match self.try_pop() {
|
|
|
|
|
Some(value) => Poll::Ready(value),
|
|
|
|
|
None => Poll::Pending,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Receiver used only by process-external inboxes. Actor and worker channels
|
|
|
|
|
/// retain the non-waking [`Receiver`] fast path below.
|
|
|
|
|
pub(crate) struct AsyncReceiver<T> {
|
|
|
|
|
queue: Arc<AsyncInboxQueue<T>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> AsyncReceiver<T> {
|
|
|
|
|
pub fn new(capacity: usize) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
queue: Arc::new(AsyncInboxQueue::new(capacity)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn try_recv(&self) -> Option<T> {
|
|
|
|
|
self.queue.try_pop()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<T> {
|
|
|
|
|
self.queue.poll_pop(cx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn new_sender(&self) -> AsyncSender<T> {
|
|
|
|
|
AsyncSender {
|
|
|
|
|
queue: self.queue.clone(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) struct AsyncSender<T> {
|
|
|
|
|
queue: Arc<AsyncInboxQueue<T>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> AsyncSender<T> {
|
|
|
|
|
pub fn send(&self, value: T) {
|
|
|
|
|
self.queue.push(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
pub(crate) struct Receiver<T> {
|
|
|
|
|
queue: Arc<HybridChannel<T>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> Receiver<T> {
|
|
|
|
|
pub fn new(capacity: usize) -> Self {
|
|
|
|
|
let queue = Arc::new(HybridChannel::new(capacity));
|
|
|
|
|
|
|
|
|
|
Self { queue }
|
|
|
|
|
}
|
|
|
|
|
pub fn try_recv(&self) -> Option<T> {
|
2026-02-09 19:05:37 +00:00
|
|
|
self.queue.pop()
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:11:03 +00:00
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
|
self.queue.is_empty()
|
|
|
|
|
}
|
|
|
|
|
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
pub fn new_sender(&self) -> Sender<T> {
|
|
|
|
|
Sender {
|
|
|
|
|
queue: self.queue.clone(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) struct Sender<T> {
|
|
|
|
|
queue: Arc<HybridChannel<T>>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 04:44:46 +00:00
|
|
|
impl<T> Clone for Sender<T> {
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
queue: self.queue.clone(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
impl<T> Sender<T> {
|
2026-02-10 07:35:58 +00:00
|
|
|
pub fn send(&self, value: T) {
|
2026-02-09 19:05:37 +00:00
|
|
|
self.queue.push(value)
|
feat: Stress tests, benchmarking, and non-failing queues and inboxes #3
Adds some basic benchmarking, stress tests. They still need to be properly examined to ensure they are testing the correct properties, but fit for "good enough". Implements the HybridChannel type, which features a channel buffer that can withstand overflows. It does so by providing a dequeue behind a mutex. Without overflow, will push messages into the lock free ArrayQueue implemented by crossbeam_queue; when that buffer fills, will use the locking portion provided by the Mutex<VecDequeue>.
In the future we can even further optimize this, perhaps with some linked list implementations of lock-free channels, but, like the benchmarks, this fits the "good enough" bar for now.
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-01-26 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
}
|