Ferrit Explore
中文·繁體·EN·日本語 Sign in Register
cielxl / veld / README.md
# veld

A high-performance HTTP server written in Rust, inspired by and wire/config-compatible with nginx.

> 一个用 Rust 编写的高性能 HTTP 服务器,配置语法兼容 nginx。在静态文件场景下,吞吐与延迟、内存占用全面优于 nginx 1.18(详见 [性能报告](#performance))。

[![Rust](https://img.shields.io/badge/rust-stable-orange.svg)](https://www.rust-lang.org/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Platform](https://img.shields.io/badge/platform-Linux%20%7C%20Windows-lightgrey.svg)]()

![veld vs nginx — throughput comparison](docs/performance.png)

<sub>Throughput vs nginx 1.18 on an 8-core Ubuntu 22.04 VM (`wrk`, interleaved peak-of-5). Full numbers in the [performance report](BENCHMARK_REPORT.md).</sub>

---

## Highlights

- **Faster than nginx on the common cases.** Small/medium static files: **+35% – +126%** throughput vs nginx 1.18, with **lower latency in every scenario** and **~1/5 the memory**.
- **nginx-compatible configuration** — drop in an `nginx.conf`-style file.
- **Zero-copy static serving** via `sendfile(2)`, an **open-file cache** (kept-open fd + precomputed response), and an **allocation-free hot path**.
- **Async core** built on [Tokio](https://tokio.rs/), one task per connection, `SO_REUSEPORT` per-worker listeners.
- **Built-in TLS** (rustls), gzip/deflate, byte-range requests, ETag / conditional requests, directory autoindex.
- **Reverse proxy & load balancing** (round-robin, least-connections, IP-hash) with health checks.
- **Cross-platform**: Linux (production, zero-copy fast paths) and Windows (development).

## Performance

Measured on an 8-core Ubuntu 22.04 VM, `wrk` load generator, both servers at 4 workers,
interleaved peak-of-5 (see [BENCHMARK_REPORT.md](BENCHMARK_REPORT.md) and the
[PDF report](report/veld-benchmark-report.pdf)).

| Scenario | Concurrency | nginx (req/s) | veld (req/s) | Δ |
|---|---|---|---|---|
| `index.html` (47 B) | 10 | 6,390 | **9,831** | **+54%** |
| `index.html` (47 B) | 100 | 11,967 | **27,061** | **+126%** |
| `index.html` (47 B) | 500 | 15,218 | **27,502** | **+81%** |
| 1 KB | 100 | 12,589 | **23,977** | **+90%** |
| 10 KB | 100 | 13,467 | **13,936** | **+3%** |
| 100 KB | 100 | 8,446 | **9,361** | **+11%** |
| 1.4 MB | 50 | **1,336** | 1,118 | −16% |
| 1.4 MB | 100 | **1,240** | 1,127 | −9% |

**Resource usage** (c=100): RSS ≈ **6 MB vs nginx 25 MB**; small-file CPU per 1000 req
**11.7 vs 25.8** (≈2.2× more efficient); **p99 latency lower in all scenarios**.

> veld wins decisively on small/medium files and is at near-parity on very large
> single downloads (a loopback-specific artifact of the async send path; see the report).

## Quick start

```bash
# 1. Install Rust (https://rustup.rs) if you don't have it
# 2. Build
cargo build --release

# 3. Run with a config
./target/release/veld -c conf/veld.conf start

# Test a config without starting
./target/release/veld -c conf/veld.conf test
```

Then open <http://localhost/> (port from the `listen` directive in your config).

## Installation

Detailed, step-by-step instructions for both platforms — including running veld as a
**systemd service** on Linux — are in **[docs/INSTALLATION.md](docs/INSTALLATION.md)**.

- **Linux**: build from source, install the binary, run as a `systemd` service.
- **Windows**: install Rust, build, run from PowerShell.

## Usage / configuration

The full command-line reference, configuration directives, signals, and examples are in
**[docs/USER_MANUAL.md](docs/USER_MANUAL.md)**.

```text
veld [OPTIONS] [COMMAND]

COMMANDS:
  start     Start the server (default)
  test      Validate the configuration file and exit
  reload    Signal a running instance to reload its configuration

OPTIONS:
  -c, --config <PATH>    Configuration file       [default: conf/veld.conf]
  -p, --prefix <PATH>    Server root prefix        [default: current dir]
      --workers <N>      Override worker count
  -h, --help             Print help
  -V, --version          Print version
```

## Project layout

```
src/
  core/        connection handling, worker pool, request pipeline
  http/        request/response types, HTTP/1.1 parser, headers
  handler/     static files, open-file cache, error pages, rewrite
  proxy/       reverse proxy, upstream pool, load balancing, health checks
  tls/         rustls integration
  config/      nginx-style config parser & directives
  log/         access & error logging
  util/        buffers, paths, signals
conf/          sample configuration
tests/         integration tests
docs/          installation guide & user manual
report/        performance report (PDF)
benchmarks/    reproducible benchmark scripts (wrk)
```

## Building from source

Requires a recent stable Rust toolchain (edition 2021; tested with 1.75+ and 1.96).

```bash
cargo build --release        # optimized binary at target/release/veld
cargo test                   # run the test suite
```

The release profile enables LTO, single codegen unit, and symbol stripping for a lean,
fast binary.

## License

MIT — see [LICENSE](LICENSE). Third-party dependency licenses are listed in
[THIRD-PARTY-LICENSES.md](THIRD-PARTY-LICENSES.md).

## Acknowledgements

Inspired by [nginx](https://nginx.org/). Built with [Tokio](https://tokio.rs/) and
[rustls](https://github.com/rustls/rustls).

## Trademark & disclaimer

veld is an independent, clean-room reimplementation written from scratch in Rust. It is
**not affiliated with, endorsed by, sponsored by, or derived from the source code of
NGINX**. "NGINX" is a registered trademark of F5, Inc.; it is referenced here only
descriptively (configuration-syntax compatibility and performance comparison). See
[NOTICE](NOTICE) for details.

Performance numbers were measured on specific hardware and configurations; results will
vary in your environment. The benchmark scripts in [`benchmarks/`](benchmarks/) let you
reproduce them. veld is provided "as is" without warranty; it has not undergone an
independent security audit — see [SECURITY.md](SECURITY.md).