ignix 0.3.0

High-performance Redis-compatible key-value store built with Rust
Documentation
# ๐Ÿ”ฅ Ignix

**High-Performance Redis-Compatible Key-Value Store**

Ignix (from "Ignite" + "Index") is a blazing-fast, Redis-protocol compatible key-value store designed for modern multi-core systems. Built with Rust for maximum performance and safety.

[![Rust](https://img.shields.io/badge/rust-1.90+-orange.svg)](https://www.rust-lang.org)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)

## โœจ Features

- ๐Ÿš€ **High Performance**: Rust + reactor/worker model for parallel execution
- ๐Ÿ”Œ **Redis Protocol Compatible**: Drop-in replacement for Redis clients
- ๐Ÿงต **Async I/O (mio)**: Non-blocking reactor + `mio::Waker` response path
- ๐Ÿ’พ **AOF Persistence**: Background writer with bounded backpressure
- ๐Ÿง  **Concurrent Storage**: `DashMap` (sharded locking) in hot path
- ๐Ÿ“Š **Benchmarks Included**: Scripts and criterion benches

## ๐Ÿ—๏ธ Architecture

Ignix v0.3.0 architecture:

- **Multi-Reactor (Thread-per-Core)**: Uses `SO_REUSEPORT` to spawn N independent worker threads (one per CPU core).
- **Shared Nothing**: Each thread has its own event loop (`mio::Poll`) and handles connections independently.
- **Zero-Lock Networking**: No shared listener lock; kernel distributes incoming connections.
- **RESP Protocol**: Full Redis Serialization Protocol support with optimized SWAR parsing.
- **Concurrent Storage**: `DashMap<Bytes, Value>` (sharded locking) for high-concurrency data access.
- **AOF Persistence**: Dedicated thread, bounded channel, periodic fsync.

## ๐Ÿš€ Quick Start

### Prerequisites

- Rust 1.80+ (recommended: latest stable)
- Cargo package manager

### Installation

```bash
git clone https://github.com/CycleChain/ignix.git
cd ignix
cargo build --release
```

### Running the Server

```bash
cargo run --release
```

The server will start on `0.0.0.0:7379` by default.

### Testing with Client Example

```bash
# In another terminal
cargo run --example client
```

Expected output:
```
+OK
$5
world
```

## ๐Ÿ“ก Supported Commands

Ignix supports the following Redis commands:

| Command | Description | Example |
|---------|-------------|---------|
| `PING` | Test connectivity | `PING` โ†’ `+PONG` |
| `SET` | Set key-value pair | `SET key value` โ†’ `+OK` |
| `GET` | Get value by key | `GET key` โ†’ `$5\r\nvalue` |
| `DEL` | Delete key | `DEL key` โ†’ `:1` |
| `EXISTS` | Check if key exists | `EXISTS key` โ†’ `:1` |
| `INCR` | Increment integer value | `INCR counter` โ†’ `:1` |
| `RENAME` | Rename a key | `RENAME old new` โ†’ `+OK` |
| `MGET` | Get multiple values | `MGET key1 key2` โ†’ `*2\r\n...` |
| `MSET` | Set multiple key-value pairs | `MSET k1 v1 k2 v2` โ†’ `+OK` |

## ๐Ÿ”ง Configuration

### Environment Variables

- `RUST_LOG`: Set logging level (e.g., `debug`, `info`, `warn`, `error`)

### AOF Persistence

Ignix automatically creates an `ignix.aof` file for persistence. Data is written to AOF and flushed every second for durability.

## ๐Ÿงช Testing

### Run Unit Tests

```bash
cargo test
```

### Run Benchmarks

```bash
# Execute benchmark
cargo bench --bench exec

# RESP parsing benchmark  
cargo bench --bench resp
```

### Example Benchmark Results

See the Performance section and `benchmark_results/benchmark_results.json`.

## ๐Ÿ”Œ Client Usage

### Using Redis CLI

```bash
redis-cli -h 127.0.0.1 -p 7379
127.0.0.1:7379> PING
PONG
127.0.0.1:7379> SET hello world
OK
127.0.0.1:7379> GET hello
"world"
```

### Using Any Redis Client Library

Ignix is compatible with any Redis client library. Here's a Python example:

```python
import redis

# Connect to Ignix
r = redis.Redis(host='localhost', port=7379, decode_responses=True)

# Use like Redis
r.set('hello', 'world')
print(r.get('hello'))  # Output: world
```

## ๐Ÿ“Š Performance

Benchmarks reflect Ignix v0.3.0. Full raw results are in `benchmarks/results/`.

### SET Throughput (ops/sec)

| Data | Conns | Redis | Ignix | Ratio (Ignix/Redis) |
|------|-------|-------|-------|----------------------|
| 64B  | 1     | 9,249 | 9,116 | 0.99x |
| 64B  | 10    | 17,628 | 22,360 | 1.27x |
| 64B  | 50    | 18,236 | 23,993 | 1.32x |
| 256B | 1     | 14,615 | 4,738 | 0.32x |
| 256B | 10    | 17,880 | 16,273 | 0.91x |
| 256B | 50    | 16,898 | 16,959 | 1.00x |
| 1KB  | 1     | 16,300 | 6,451 | 0.40x |
| 1KB  | 10    | 16,936 | 24,323 | 1.44x |
| 1KB  | 50    | 3,313 | 7,314 | 2.21x |
| 4KB  | 1     | 11,286 | 8,581 | 0.76x |
| 4KB  | 10    | 17,232 | 27,933 | 1.62x |
| 4KB  | 50    | 16,343 | 20,675 | 1.27x |

### GET Throughput (ops/sec)

| Data | Conns | Redis | Ignix | Ratio (Ignix/Redis) |
|------|-------|-------|-------|----------------------|
| 64B  | 1     | 19,612 | 10,121 | 0.52x |
| 64B  | 10    | 16,780 | 26,341 | 1.57x |
| 64B  | 50    | 14,948 | 26,766 | 1.79x |
| 256B | 1     | 20,035 | 3,245 | 0.16x |
| 256B | 10    | 15,164 | 51,678 | 3.41x |
| 256B | 50    | 15,619 | 18,508 | 1.18x |
| 1KB  | 1     | 17,525 | 10,436 | 0.60x |
| 1KB  | 10    | 11,930 | 23,184 | 1.94x |
| 1KB  | 50    | 2,491 | 1,687 | 0.68x |
| 4KB  | 1     | 16,600 | 8,733 | 0.53x |
| 4KB  | 10    | 7,532 | 20,399 | 2.71x |
| 4KB  | 50    | 13,035 | 24,078 | 1.85x |

### Real-World Scenario (Session Store)

| Metric | Redis | Ignix | Ratio (Ignix/Redis) |
|--------|-------|-------|----------------------|
| Throughput | 3,201 ops/sec | 3,996 ops/sec | **1.25x** |
| Avg Latency | 13.56 ms | 10.38 ms | **0.76x** |

Notes:
- Values rounded from `benchmark_results/benchmark_results.json`.
- All runs showed 0 errors, 100% success.

### ๐Ÿ“Š Benchmark Your Own Workload

Run comprehensive benchmarks with our included tools:

```bash
# Quick comparison
python3 quick_benchmark.py

# Detailed analysis with charts
python3 benchmark_redis_vs_ignix.py

# Custom test scenarios
python3 benchmark_redis_vs_ignix.py --data-sizes 64 256 1024 --connections 1 10 25
```

**Architecture Benefits:**
- **Sub-millisecond latency** for most operations
- **High throughput** with async I/O
- **Memory efficient** with zero-copy operations where possible
- **Minimal allocations** in hot paths

## ๐Ÿ—๏ธ Development

### Project Structure

```
src/
โ”œโ”€โ”€ bin/ignix.rs        # Server binary
โ”œโ”€โ”€ lib.rs              # Library exports
โ”œโ”€โ”€ protocol.rs         # RESP protocol parser/encoder
โ”œโ”€โ”€ storage.rs          # In-memory storage (Dict)
โ”œโ”€โ”€ shard.rs           # Command execution logic  
โ”œโ”€โ”€ net.rs             # Networking and event loop
โ””โ”€โ”€ aof.rs             # AOF persistence

examples/
โ””โ”€โ”€ client.rs          # Example client

tests/
โ”œโ”€โ”€ basic.rs           # Basic functionality tests
โ””โ”€โ”€ resp.rs            # Protocol parsing tests

benches/
โ”œโ”€โ”€ exec.rs            # Command execution benchmarks
โ””โ”€โ”€ resp.rs            # Protocol parsing benchmarks
```

### Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add tests for new functionality
5. Run tests (`cargo test`)
6. Run benchmarks (`cargo bench`)
7. Commit your changes (`git commit -m 'Add amazing feature'`)
8. Push to the branch (`git push origin feature/amazing-feature`)
9. Open a Pull Request

### Code Style

- Follow Rust standard formatting (`cargo fmt`)
- Run Clippy lints (`cargo clippy`)
- Maintain test coverage for new features

## ๐Ÿ” Debugging

Enable debug logging: `RUST_LOG=debug cargo run --release`
Monitor AOF: `tail -f ignix.aof`

## ๐Ÿšง Roadmap (Short)

- More Redis commands (HASH/LIST/SET)
- RDB snapshots, metrics/monitoring
- Clustering and replication

## ๐Ÿ› Known Limitations

- Limited command set vs Redis (expanding)
- No clustering or replication yet
- RDB snapshots not yet available

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- [Redis]https://redis.io/ for the protocol specification
- [mio]https://github.com/tokio-rs/mio for async I/O
- The Rust community for excellent tooling and libraries

## ๐Ÿ“ž Support

- **Issues**: [GitHub Issues]https://github.com/CycleChain/ignix/issues
- **Discussions**: [GitHub Discussions]https://github.com/CycleChain/ignix/discussions

---

**Built with โค๏ธ and ๐Ÿฆ€ by the [CycleChain.io](https://cyclechain.io) team**