rename worker to actor
This commit is contained in:
		@@ -1,20 +1,20 @@
 | 
			
		||||
# Minimal Rhailib Benchmark
 | 
			
		||||
# Minimal baobab Benchmark
 | 
			
		||||
 | 
			
		||||
A simplified, minimal benchmarking tool for rhailib performance testing.
 | 
			
		||||
A simplified, minimal benchmarking tool for baobab performance testing.
 | 
			
		||||
 | 
			
		||||
## Overview
 | 
			
		||||
 | 
			
		||||
This benchmark focuses on simplicity and direct timing measurements:
 | 
			
		||||
- Creates a single task (n=1) using Lua script
 | 
			
		||||
- Measures latency using Redis timestamps
 | 
			
		||||
- Uses existing worker binary
 | 
			
		||||
- Uses existing actor binary
 | 
			
		||||
- ~85 lines of code total
 | 
			
		||||
 | 
			
		||||
## Usage
 | 
			
		||||
 | 
			
		||||
### Prerequisites
 | 
			
		||||
- Redis running on `127.0.0.1:6379`
 | 
			
		||||
- Worker binary built: `cd src/worker && cargo build --release`
 | 
			
		||||
- Actor binary built: `cd src/actor && cargo build --release`
 | 
			
		||||
 | 
			
		||||
### Run Benchmark
 | 
			
		||||
```bash
 | 
			
		||||
@@ -25,7 +25,7 @@ cargo bench
 | 
			
		||||
### Expected Output
 | 
			
		||||
```
 | 
			
		||||
🧹 Cleaning up Redis...
 | 
			
		||||
🚀 Starting worker...
 | 
			
		||||
🚀 Starting actor...
 | 
			
		||||
📝 Creating single task...
 | 
			
		||||
⏱️  Waiting for completion...
 | 
			
		||||
✅ Task completed in 23.45ms
 | 
			
		||||
@@ -42,10 +42,10 @@ cargo bench
 | 
			
		||||
## How It Works
 | 
			
		||||
 | 
			
		||||
1. **Cleanup**: Clear Redis queues and task details
 | 
			
		||||
2. **Start Worker**: Spawn single worker process
 | 
			
		||||
2. **Start Actor**: Spawn single actor process
 | 
			
		||||
3. **Create Task**: Use Lua script to create one task with timestamp
 | 
			
		||||
4. **Wait & Measure**: Poll task until complete, calculate latency
 | 
			
		||||
5. **Cleanup**: Kill worker and clear Redis
 | 
			
		||||
5. **Cleanup**: Kill actor and clear Redis
 | 
			
		||||
 | 
			
		||||
## Latency Calculation
 | 
			
		||||
 | 
			
		||||
@@ -55,7 +55,7 @@ latency_ms = updated_at - created_at
 | 
			
		||||
 | 
			
		||||
Where:
 | 
			
		||||
- `created_at`: Timestamp when task was created (Lua script)
 | 
			
		||||
- `updated_at`: Timestamp when worker completed task
 | 
			
		||||
- `updated_at`: Timestamp when actor completed task
 | 
			
		||||
 | 
			
		||||
## Future Iterations
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ if task_count <= 0 or task_count > 10000 then
 | 
			
		||||
    return redis.error_reply("task_count must be a positive integer between 1 and 10000")
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Get current timestamp in Unix seconds (to match worker expectations)
 | 
			
		||||
-- Get current timestamp in Unix seconds (to match actor expectations)
 | 
			
		||||
local rhai_task_queue = 'rhai_tasks:' .. circle_name
 | 
			
		||||
local task_keys = {}
 | 
			
		||||
local current_time = redis.call('TIME')[1]
 | 
			
		||||
@@ -35,7 +35,7 @@ for i = 1, task_count do
 | 
			
		||||
        'task_sequence', tostring(i)
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    -- Queue the task for workers
 | 
			
		||||
    -- Queue the task for actors
 | 
			
		||||
    redis.call('LPUSH', rhai_task_queue, task_id)
 | 
			
		||||
    
 | 
			
		||||
    -- Add key to return array
 | 
			
		||||
 
 | 
			
		||||
@@ -23,23 +23,23 @@ fn cleanup_redis() -> Result<(), redis::RedisError> {
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn start_worker() -> Result<Child, std::io::Error> {
 | 
			
		||||
fn start_actor() -> Result<Child, std::io::Error> {
 | 
			
		||||
    Command::new("cargo")
 | 
			
		||||
        .args(&[
 | 
			
		||||
            "run",
 | 
			
		||||
            "--release",
 | 
			
		||||
            "--bin",
 | 
			
		||||
            "worker",
 | 
			
		||||
            "actor",
 | 
			
		||||
            "--",
 | 
			
		||||
            "--circle",
 | 
			
		||||
            CIRCLE_NAME,
 | 
			
		||||
            "--redis-url",
 | 
			
		||||
            REDIS_URL,
 | 
			
		||||
            "--worker-id",
 | 
			
		||||
            "bench_worker",
 | 
			
		||||
            "--actor-id",
 | 
			
		||||
            "bench_actor",
 | 
			
		||||
            "--preserve-tasks",
 | 
			
		||||
        ])
 | 
			
		||||
        .current_dir("src/worker")
 | 
			
		||||
        .current_dir("src/actor")
 | 
			
		||||
        .stdout(Stdio::null())
 | 
			
		||||
        .stderr(Stdio::null())
 | 
			
		||||
        .spawn()
 | 
			
		||||
@@ -126,26 +126,26 @@ fn wait_for_batch_completion(task_keys: &[String]) -> Result<f64, Box<dyn std::e
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn cleanup_worker(mut worker: Child) -> Result<(), std::io::Error> {
 | 
			
		||||
    worker.kill()?;
 | 
			
		||||
    worker.wait()?;
 | 
			
		||||
fn cleanup_actor(mut actor: Child) -> Result<(), std::io::Error> {
 | 
			
		||||
    actor.kill()?;
 | 
			
		||||
    actor.wait()?;
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn bench_single_rhai_task(c: &mut Criterion) {
 | 
			
		||||
    // Setup: ensure worker is built
 | 
			
		||||
    // Setup: ensure actor is built
 | 
			
		||||
    let _ = Command::new("cargo")
 | 
			
		||||
        .args(&["build", "--release", "--bin", "worker"])
 | 
			
		||||
        .current_dir("src/worker")
 | 
			
		||||
        .args(&["build", "--release", "--bin", "actor"])
 | 
			
		||||
        .current_dir("src/actor")
 | 
			
		||||
        .output()
 | 
			
		||||
        .expect("Failed to build worker");
 | 
			
		||||
        .expect("Failed to build actor");
 | 
			
		||||
 | 
			
		||||
    // Clean up before starting
 | 
			
		||||
    cleanup_redis().expect("Failed to cleanup Redis");
 | 
			
		||||
 | 
			
		||||
    // Start worker once and reuse it
 | 
			
		||||
    let worker = start_worker().expect("Failed to start worker");
 | 
			
		||||
    thread::sleep(Duration::from_millis(1000)); // Give worker time to start
 | 
			
		||||
    // Start actor once and reuse it
 | 
			
		||||
    let actor = start_actor().expect("Failed to start actor");
 | 
			
		||||
    thread::sleep(Duration::from_millis(1000)); // Give actor time to start
 | 
			
		||||
 | 
			
		||||
    let mut group = c.benchmark_group("rhai_task_execution");
 | 
			
		||||
    group.sample_size(10); // Reduce sample size
 | 
			
		||||
@@ -174,8 +174,8 @@ fn bench_single_rhai_task(c: &mut Criterion) {
 | 
			
		||||
 | 
			
		||||
    group.finish();
 | 
			
		||||
 | 
			
		||||
    // Cleanup worker
 | 
			
		||||
    cleanup_worker(worker).expect("Failed to cleanup worker");
 | 
			
		||||
    // Cleanup actor
 | 
			
		||||
    cleanup_actor(actor).expect("Failed to cleanup actor");
 | 
			
		||||
    cleanup_redis().expect("Failed to cleanup Redis");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user