A lightweight, high-performance Content Delivery Network (CDN) built with Rust and Axum. MiniCDN serves static files with built-in compression, CORS support, and request tracing.
- 🚀 High Performance: Built with Rust and Axum for maximum performance
- 📁 Static File Serving: Efficiently serves files from the
staticdirectory - 🗜️ Compression: Automatic gzip compression with precompressed file support
- 🌐 CORS Support: Permissive CORS configuration for cross-origin requests
- 📊 Request Tracing: Built-in HTTP request logging and tracing
- ⚡ Async/Await: Fully asynchronous request handling with Tokio
- Rust 1.70+ (Edition 2024)
- Cargo
- Clone the repository:
git clone <repository-url>
cd minicdn- Build and run the service:
cargo runThe service will start on http://0.0.0.0:8180
For development with auto-reload:
cargo install cargo-watch
cargo watch -x runOnce the service is running, you can access your static files through HTTP:
- Base URL:
http://localhost:8180/ - Static Files: Place files in the
static/directory
The service currently includes example files in the static/ directory:
image.jpeg- Sample image filevid.mp4- Sample video filer.md- Sample markdown file
# Access an image
curl http://localhost:8180/image.jpeg
# Access a video
curl http://localhost:8180/vid.mp4
# Access a markdown file
curl http://localhost:8180/r.mdThe service runs on port 8180 by default. To change the port, modify the addr variable in src/main.rs:
let addr = SocketAddr::from(([0, 0, 0, 0], 8180)); // Change 8180 to your desired portLogging is configured to show info-level logs for the minicdn service and tower_http middleware. You can adjust the log level by setting the RUST_LOG environment variable:
RUST_LOG=debug cargo run # For debug logs
RUST_LOG=warn cargo run # For warning logs onlyBy default, files are served from the static/ directory. To change this, modify the serve_dir configuration in src/main.rs:
let serve_dir = ServeDir::new("your-directory").precompressed_gzip();MiniCDN is built using:
- Axum: Modern, ergonomic web framework
- Tower HTTP: HTTP-specific middleware and utilities
- Tokio: Asynchronous runtime
- Tracing: Application-level tracing framework
- TraceLayer: HTTP request/response logging
- CompressionLayer: Automatic response compression
- CorsLayer: Cross-Origin Resource Sharing support
- ServeDir: Static file serving with precompressed gzip support
- Precompressed Files: Automatically serves
.gzfiles if available - Async I/O: Non-blocking file operations
- Zero-Copy: Efficient file streaming
- HTTP Keep-Alive: Connection reuse for better performance
MiniCDN can handle high concurrent loads efficiently. You can test performance using wrk, a modern HTTP benchmarking tool.
macOS (using Homebrew):
brew install wrkUbuntu/Debian:
sudo apt-get install wrkCentOS/RHEL:
sudo yum install wrkBuilding from source:
git clone https://github.com/wg/wrk.git
cd wrk
make
sudo cp wrk /usr/local/binTest your MiniCDN instance with high concurrency:
# Stress test with 8 threads and 1000 connections for 30 seconds
wrk -t8 -c1000 -d30s http://127.0.0.1:8180/vid.mp4Here's an example performance test result serving a video file:
Running 30s test @ http://127.0.0.1:8180/vid.mp4
8 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 777.32ms 382.36ms 1.98s 82.14%
Req/Sec 3.52 4.48 30.00 83.33%
367 requests in 30.08s, 52.00GB read
Socket errors: connect 0, read 44974, write 0, timeout 31
Requests/sec: 12.20
Transfer/sec: 1.73GB
Performance Highlights:
- Throughput: 1.73GB/sec data transfer
- Total Data: 52GB served in 30 seconds
- Concurrent Connections: Handled 1000 concurrent connections
- File Size: Large video files served efficiently
Note: Performance results may vary based on hardware, network conditions, file sizes, and system configuration. For optimal performance, use release builds (
cargo build --release).
# Debug build
cargo build
# Release build (optimized)
cargo build --releasecargo testcargo fmtcargo clippyCreate a Dockerfile for containerized deployment:
FROM rust:1.70 as builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/minicdn /usr/local/bin/minicdn
COPY static/ /app/static/
WORKDIR /app
EXPOSE 8180
CMD ["minicdn"]This project is open source. Please add your preferred license.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- Configuration file support
- Custom header support
- Rate limiting
- File upload endpoints
- Directory browsing
- SSL/TLS support
- Metrics and monitoring endpoints