Skip to content

A lightweight CDN service written in Go, built to serve static assets and video content with minimal latency and optimal resource efficiency. Designed with simplicity and maintainability in mind, it leverages Go’s built-in concurrency, robust HTTP stack, and streaming support to deliver high availability and consistent performance

Notifications You must be signed in to change notification settings

maasumiyaat/runcdn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RunCDN - High-Performance Static File Server

A lightweight, high-performance static file server written in Go with automatic gzip compression, CORS support, and optimized for serving large files efficiently.

Features

  • 🚀 High Performance: Optimized for serving static files with minimal overhead
  • 📦 Automatic Gzip Compression: Reduces bandwidth usage for compatible clients
  • 🌐 CORS Support: Cross-Origin Resource Sharing enabled for all origins
  • 📊 Request Logging: Built-in logging with timing information
  • Configurable Timeouts: Optimized timeout settings for large file transfers
  • 🔧 Simple Configuration: Minimal setup required

Quick Start

Prerequisites

  • Go 1.24.4 or later
  • wrk (for load testing)

Installation

  1. Clone the repository:
git clone <repository-url>
cd runcdn
  1. Install dependencies:
go mod download
  1. Build and run:
go build -o runcdn main.go
./runcdn

The server will start on http://localhost:8181 and serve files from the ./static directory.

Adding Static Files

Place your static files in the static/ directory. The server will serve them directly:

  • http://localhost:8181/image.jpeg
  • http://localhost:8181/vid.mp4
  • http://localhost:8181/r.md

Load Testing

Installing wrk

macOS (using Homebrew):

brew install wrk

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install wrk

Build from source:

git clone https://github.com/wg/wrk.git
cd wrk
make
sudo cp wrk /usr/local/bin/

Running Load Tests

To stress test the server with 8 threads and 1000 concurrent connections for 30 seconds:

wrk -t8 -c1000 -d30s http://127.0.0.1:8181/vid.mp4

Parameters:

  • -t8: Use 8 threads
  • -c1000: Maintain 1000 concurrent connections
  • -d30s: Run test for 30 seconds
  • http://127.0.0.1:8181/vid.mp4: Target URL (replace with your file)

Performance Benchmarks

Based on load testing with wrk -t8 -c1000 -d30s:

Latest Results

  • Requests/sec: 455.98
  • Transfer/sec: 4.30GB
  • Average Latency: 118.35ms
  • Total Requests: 13,726 in 30.10s
  • Data Transferred: 129.38GB

Historical Comparison

See compare.txt for detailed performance comparisons with other implementations.

Configuration

The server uses the following default settings:

  • Port: 8181
  • Static Directory: ./static
  • Read Timeout: 10 seconds
  • Write Timeout: 60 seconds
  • Idle Timeout: 120 seconds

To modify these settings, edit the variables in main.go.

Architecture

The server implements several middleware layers:

  1. Logging Middleware: Records request method, path, and response time
  2. Gzip Middleware: Automatically compresses responses when supported by client
  3. CORS Middleware: Enables cross-origin requests
  4. File Server: Serves static files from the configured directory

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is open source and available under the MIT License.

About

A lightweight CDN service written in Go, built to serve static assets and video content with minimal latency and optimal resource efficiency. Designed with simplicity and maintainability in mind, it leverages Go’s built-in concurrency, robust HTTP stack, and streaming support to deliver high availability and consistent performance

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages