Skip to content

vaxp/venom_memory_rs

Repository files navigation

🐍 VenomMemory Rust

IPC library in Rust.

Performance Latency License

An inter-process communication (IPC) library based on Shared Memory with Lock-Free design to achieve maximum possible performance.

🚀 Proven Performance

Note: Test ran for 20 minutes Breaking the previous record (23.3 GB/s) and achieving:

  • Bandwidth: 37.52 GB/s (+61%)
  • Throughput: > 70,000 req/s
  • Utilization: 98% of theoretical DDR4 memory limit

📦 Installation

Add the library to your Cargo.toml:

[dependencies]
venom_memory = { path = "." } # or git link

🛠️ How to Use

The library is based on a Daemon (Writer) and Shell (Reader) architecture:

1. Server (Writer / Daemon)

The server is responsible for creating and managing the channel. It is the only one who writes the data that everyone sees.

use venom_memory::{DaemonChannel, ChannelConfig};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Configure the channel
    let config = ChannelConfig {
        data_size: 64 * 1024, // 64KB data size
        cmd_slots: 128,       // Number of commands in queue
        max_clients: 16,      // Maximum number of clients
    };

    // 2. Create channel named "my_channel"
    let daemon = DaemonChannel::create("my_channel", config)?;
    println!("Daemon started on channel: my_channel");

    // 3. Listen and handle commands
    daemon.run(|client_id, cmd| {
        // Convert command to text
        let cmd_str = String::from_utf8_lossy(cmd);
        println!("Received from {}: {}", client_id, cmd_str);

        // Execute logic and return response
        if cmd_str.contains("ping") {
            return b"pong".to_vec();
        }

        // Write data visible to everyone (state update)
        // daemon.write_data(b"New Global State Here");

        b"Unknown command".to_vec()
    });

    Ok(())
}

2. Client (Reader / Shell)

The client connects to the channel, reads data instantaneously, and sends commands to the server.

use venom_memory::ShellChannel;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Connect to the channel
    let shell = ShellChannel::connect("my_channel")?;
    println!("Connected with Client ID: {}", shell.client_id());

    // 2. Read current data (without waiting/locking)
    let mut data_buf = [0u8; 1024];
    let len = shell.read_data(&mut data_buf);
    println!("Current Data: {:?}", &data_buf[..len]);

    // 3. Send command and wait for response (RPC style)
    let mut response_buf = [0u8; 1024];
    let resp_len = shell.request(b"ping", &mut response_buf);
    
    let response = String::from_utf8_lossy(&response_buf[..resp_len]);
    println!("Server Response: {}", response);

    Ok(())
}

🔄 How Does Communication Work?

  1. Reading (SeqLock):

    • The server writes data.
    • Clients read data directly without any locks (Lock-Free).
    • If a write occurs during reading, the library automatically retries (guarantees consistent reads).
  2. Writing (MPSC Queue):

    • Clients send commands to the Commands queue.
    • The server pulls commands one by one and processes them.
    • The server writes the response in the shared data area or a dedicated response area.

🌟 Capabilities and Use Cases

1. Financial Trading Applications (HFT & Fintech)

  • Capability: Latency less than 50 microseconds.
  • Usage: Transfer market data and execute orders between trading algorithms and exchange gateways on the same server at speeds that exceed TCP/IP networks by hundreds of times.

2. Real-time Video Processing

  • Capability: 98% of theoretical memory limit
  • Usage:
    • Transfer 8K Raw uncompressed video frames (only requires ~2-4 GB/s!).
    • Transfer data between AI Inference processes and Rendering processes.

3. Game Engines and Simulation Systems

  • Capability: Update state over 20 million times without performance degradation.
  • Usage: Separate Physics, AI, and Networking in separate processes to protect the game from crashes (Crash Safe) while maintaining "sub-frame" synchronization.

4. Robotics and Embedded Systems

  • Capability: Lock-free reads (no system-stopping locks).
  • Usage: Share sensor data (Lidar, Cameras, IMU) between different control systems without risk of system deadlock.

5. Databases and Locally Distributed Systems

  • Usage: As an ultra-fast data transport layer between Shards or Sidecars in microservices infrastructure running on the same machine.

⚠️ System Requirements

  • CPU: x86_64 recommended (to ensure fast atomic operations).
  • Rust: Stable 1.70+.

venom_memory_rs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published