Module pool

Module pool 

Source
Expand description

Message pooling for memory efficiency

This module provides object pooling for messages to reduce allocation overhead in high-throughput scenarios. By reusing message structures, we can significantly reduce GC pressure and improve performance.

§Examples

use celers_protocol::pool::{MessagePool, PooledMessage};
use uuid::Uuid;

// Create a message pool
let pool = MessagePool::new();

// Acquire a pooled message
let mut msg = pool.acquire();
msg.headers.task = "tasks.add".to_string();
msg.headers.id = Uuid::new_v4();
msg.body = vec![1, 2, 3];

// When dropped, the message is returned to the pool
drop(msg);

// The next acquire will reuse the same allocation
let msg2 = pool.acquire();
assert_eq!(pool.size(), 0); // Pool is now empty

Structs§

MessagePool
A pool of reusable messages
PooledMessage
A pooled message that automatically returns to the pool when dropped
PooledTaskArgs
Pooled task arguments
TaskArgsPool
A pool of reusable task arguments