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.
2026-01-26 07:14:00 +00:00
|
|
|
//! Saturation stress tests - find where the runtime breaks.
|
|
|
|
|
//!
|
|
|
|
|
//! These tests intentionally push past limits to document failure modes.
|
|
|
|
|
|
|
|
|
|
use super::{BlackHole, Counter, Msg, Stress, StressResult};
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
use swactor::runtime::{Runtime, RuntimeConfig};
|
|
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
/// Blast the transfer queue (replaces router_inbox_overflow)
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
#[test]
|
|
|
|
|
#[cfg(feature = "stress")]
|
2026-02-05 15:54:03 +00:00
|
|
|
fn transfer_queue_overflow() {
|
|
|
|
|
println!("\n>>> STRESS: Transfer Queue Overflow");
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
|
|
|
|
|
let config = RuntimeConfig {
|
|
|
|
|
max_actors: 10,
|
2026-02-05 15:54:03 +00:00
|
|
|
actor_max_messages: 100, // Tiny buffer
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
num_threads: 1,
|
2026-02-06 06:48:51 +00:00
|
|
|
..Default::default()
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
};
|
|
|
|
|
let runtime = Runtime::new(config);
|
|
|
|
|
let sink = runtime.spawn(BlackHole).unwrap();
|
|
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
// Process spawn
|
|
|
|
|
runtime.tick();
|
|
|
|
|
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
// Blast messages without processing
|
2026-02-05 15:54:03 +00:00
|
|
|
let mut result = StressResult::new("transfer_queue_overflow");
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
let start = std::time::Instant::now();
|
|
|
|
|
|
|
|
|
|
for _ in 0..10_000 {
|
|
|
|
|
result.operations += 1;
|
|
|
|
|
if runtime.send_to::<Msg>(sink, Msg).is_ok() {
|
|
|
|
|
result.successes += 1;
|
|
|
|
|
} else {
|
|
|
|
|
result.failures += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.duration = start.elapsed();
|
2026-02-05 15:54:03 +00:00
|
|
|
result.note(format!("Transfer buffer: 100, Messages sent: 10,000"));
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
// With hybrid channel, no failures expected
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
assert_eq!(result.failures, 0, "Hybrid channel should not reject");
|
|
|
|
|
result.print();
|
2026-02-05 15:54:03 +00:00
|
|
|
println!(">>> PASS: Hybrid channel prevented transfer queue overflow\n");
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
/// Blast a single actor's mailbox via transfer queue
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
#[test]
|
|
|
|
|
#[cfg(feature = "stress")]
|
|
|
|
|
fn actor_inbox_overflow() {
|
|
|
|
|
println!("\n>>> STRESS: Actor Inbox Overflow");
|
|
|
|
|
|
|
|
|
|
let config = RuntimeConfig {
|
|
|
|
|
max_actors: 10,
|
2026-02-05 15:54:03 +00:00
|
|
|
actor_max_messages: 100_000, // Large transfer buffer
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
num_threads: 1,
|
2026-02-06 06:48:51 +00:00
|
|
|
..Default::default()
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
};
|
|
|
|
|
let runtime = Runtime::new(config);
|
|
|
|
|
let sink = runtime.spawn(Counter::new()).unwrap();
|
|
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
// Process spawn
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
runtime.tick();
|
|
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
// Now blast messages
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
let mut sent = 0u64;
|
2026-02-05 15:54:03 +00:00
|
|
|
let mut failed = 0u64;
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
for _ in 0..10_000 {
|
|
|
|
|
if runtime.send_to::<Msg>(sink, Msg).is_ok() {
|
|
|
|
|
sent += 1;
|
|
|
|
|
} else {
|
2026-02-05 15:54:03 +00:00
|
|
|
failed += 1;
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
}
|
2026-02-05 15:54:03 +00:00
|
|
|
// Tick occasionally to let worker deliver
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
if sent % 100 == 0 {
|
|
|
|
|
runtime.tick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process all remaining messages
|
|
|
|
|
for _ in 0..5000 {
|
|
|
|
|
runtime.tick();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
println!(" Sent: {}", sent);
|
|
|
|
|
println!(" Failed: {}", failed);
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
assert_eq!(failed, 0, "Transfer queue rejected message under load");
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
println!(">>> PASS: No message loss with hybrid channel\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Blast the runtime with actor spawns
|
|
|
|
|
#[test]
|
|
|
|
|
#[cfg(feature = "stress")]
|
|
|
|
|
fn actor_queue_overflow() {
|
|
|
|
|
println!("\n>>> STRESS: Actor Queue Overflow");
|
|
|
|
|
|
|
|
|
|
let config = RuntimeConfig {
|
|
|
|
|
max_actors: 100, // Small actor queue
|
|
|
|
|
actor_max_messages: 100,
|
|
|
|
|
num_threads: 1,
|
2026-02-06 06:48:51 +00:00
|
|
|
..Default::default()
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
};
|
|
|
|
|
let runtime = Runtime::new(config);
|
|
|
|
|
|
|
|
|
|
let mut result = StressResult::new("actor_queue_overflow");
|
|
|
|
|
let start = std::time::Instant::now();
|
|
|
|
|
|
|
|
|
|
// Try to spawn 500 actors into 100-slot queue
|
|
|
|
|
for _ in 0..500 {
|
|
|
|
|
result.operations += 1;
|
|
|
|
|
match runtime.spawn(BlackHole) {
|
|
|
|
|
Ok(_) => result.successes += 1,
|
|
|
|
|
Err(_) => result.failures += 1,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.duration = start.elapsed();
|
|
|
|
|
result.note(format!("Queue capacity: 100, Spawn attempts: 500"));
|
|
|
|
|
result.print();
|
|
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
// Note: With hybrid channel (overflow to SegQueue), we expect no failures
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
assert_eq!(
|
|
|
|
|
result.failures, 0,
|
|
|
|
|
"Spawned more actors than queue capacity"
|
|
|
|
|
);
|
2026-02-05 15:54:03 +00:00
|
|
|
println!(">>> PASS: Actor queue correctly handles overflow\n");
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sustained overload - run at 2x capacity for extended period.
|
|
|
|
|
/// Documents: Does the system degrade gracefully or crash?
|
|
|
|
|
#[test]
|
|
|
|
|
#[cfg(feature = "stress")]
|
|
|
|
|
fn sustained_overload() {
|
|
|
|
|
println!("\n>>> STRESS: Sustained Overload");
|
|
|
|
|
|
|
|
|
|
let config = RuntimeConfig {
|
|
|
|
|
max_actors: 100,
|
2026-02-05 15:54:03 +00:00
|
|
|
actor_max_messages: 1000,
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
num_threads: 1,
|
2026-02-06 06:48:51 +00:00
|
|
|
..Default::default()
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
};
|
|
|
|
|
let runtime = Runtime::new(config);
|
|
|
|
|
|
|
|
|
|
// Spawn some actors
|
|
|
|
|
let mut actors = Vec::new();
|
|
|
|
|
for _ in 0..50 {
|
|
|
|
|
if let Ok(addr) = runtime.spawn(Counter::new()) {
|
|
|
|
|
actors.push(addr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 15:54:03 +00:00
|
|
|
// Process spawn registrations
|
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.
2026-01-26 07:14:00 +00:00
|
|
|
for _ in 0..200 {
|
|
|
|
|
runtime.tick();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let result = Stress::new("sustained_overload")
|
|
|
|
|
.for_duration(Duration::from_secs(2))
|
|
|
|
|
.run(|| {
|
|
|
|
|
// Send to random actor
|
|
|
|
|
let idx = (std::time::Instant::now().elapsed().as_nanos() as usize) % actors.len();
|
|
|
|
|
let success = runtime.send_to::<Msg>(actors[idx], Msg).is_ok();
|
|
|
|
|
|
|
|
|
|
// Process some (but not all) - simulating overload
|
|
|
|
|
runtime.tick();
|
|
|
|
|
|
|
|
|
|
success
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
result.print();
|
|
|
|
|
println!(">>> System survived sustained overload without panic\n");
|
|
|
|
|
}
|