Files
SpeedtestServer-test/README.md
2026-02-22 23:47:58 +03:00

2.0 KiB

Speedtest Server

A lightweight HTTP server written in Go for measuring network bandwidth. Provides download and upload endpoints that clients can use to benchmark their connection speed.

How It Works

  • Download test — the server streams a requested number of bytes of random data to the client. The random pool (4 MB) is generated once at startup and cycled to fulfill any size request without disk I/O.
  • Upload test — the client POSTs arbitrary data; the server reads and discards it, then responds with 200 OK.

Endpoints

Method Path Description
GET /download?bytes=<size> Stream <size> bytes of random data
POST /upload Consume uploaded data and acknowledge

Examples

# Download 100 MB and measure throughput
curl -o /dev/null -w "%{speed_download} bytes/s\n" \
  "http://localhost:8080/download?bytes=104857600"

# Upload 50 MB and measure throughput
curl -X POST -o /dev/null -w "%{speed_upload} bytes/s\n" \
  --data-binary @/dev/urandom \
  --limit-rate 50M \
  "http://localhost:8080/upload"

Running

Locally (requires Go 1.21+)

go run main.go

The server starts on port 8080.

Docker

docker build -t speedtest-server .
docker run -p 8080:8080 speedtest-server

Docker Compose

docker compose up -d

The service restarts automatically unless explicitly stopped.

Docker Image

The image uses a two-stage build:

  1. Buildergolang:1.25-alpine compiles a statically linked binary with debug info stripped (-ldflags="-w -s").
  2. Runtimegcr.io/distroless/static-debian12 — a minimal, shell-less base image. The binary runs as nonroot:nonroot.

Configuration

Parameter Default Description
Port 8080 Hardcoded in main.go
Random pool size 4 MB Pre-generated at startup
Upload read buffer 32 KB Per-request buffer size