Skip to content

AyushWalekar/docker-benchmark

Repository files navigation

docker-test

This repository compares Docker image and container performance (image size, cold start time, warmup time, memory usage, CPU usage, etc.) across various languages and frameworks.

Languages and Runtimes

  • GoLang (Go 1.21, Alpine-based)
  • Node.js (Node 22, Alpine-based)
  • Node.js TypeScript (Node 22 with TypeScript compilation, Alpine-based)
  • Bun (Bun 1.x, Alpine-based)
  • Deno (Deno 2.1.4)

Each implementation provides the same set of API endpoints for fair performance comparison.

Project Structure

docker-test/
├── golang/                    # Go implementation (basic endpoints)
├── nodejs/                    # Node.js implementation (basic endpoints)
├── nodejs-typescript/         # TypeScript implementation (basic endpoints)
├── bun/                       # Bun implementation (basic endpoints)
├── deno/                      # Deno implementation (basic endpoints)
├── golang-mongo/              # Go + MongoDB (raw driver) - Accounts Payable
├── golang-mongo-orm/          # Go + MongoDB + MGM ORM - Accounts Payable
├── nodejs-express-mongo/      # Node.js + Express + Mongoose - Accounts Payable
├── shared/                    # Shared test data and DB init script
├── benchmark/                 # Benchmark scripts
├── docker-compose.yml         # Docker Compose for basic implementations
├── ACCOUNTS_PAYABLE.md        # Accounts Payable implementations overview
├── QUICKSTART_AP.md           # Quick start guide for AP implementations
└── *.sh                       # Helper scripts

API Endpoints

All implementations provide these endpoints on port 8080:

  • GET /hello-world — Simple health check (cold start and minimal response time)
  • POST /echo — Returns posted JSON/body (request parsing and JSON serialization)
  • GET /compute — Fibonacci(30) calculation (CPU performance)
  • GET /data — Returns 100 JSON objects (memory and network transfer)
  • GET /file-read — Reads a static file (file I/O read performance)
  • POST /file-write — Writes data to file (file I/O write performance)
  • GET /db-read — Reads from PostgreSQL (database read performance)
  • POST /db-write — Inserts into PostgreSQL (database write performance)

Quick Start

Prerequisites

  • Docker and Docker Compose
  • curl (for testing)
  • jq (optional, for pretty JSON output)
  • bc (for benchmark calculations)

1. Build All Images

./build-all.sh

This builds Docker images for all runtimes.

2. Start All Services

./run-all.sh

This starts all containers and PostgreSQL. Services will be available at:

3. Test Endpoints

Test all endpoints for a specific runtime:

./test-endpoints.sh 8081  # Test GoLang
./test-endpoints.sh 8082  # Test Node.js
./test-endpoints.sh 8083  # Test TypeScript
./test-endpoints.sh 8084  # Test Bun
./test-endpoints.sh 8085  # Test Deno

4. Run Benchmarks

./benchmark/benchmark.sh

This script measures:

  1. Image sizes (compressed and uncompressed)
  2. Cold start time (container restart to first response)
  3. Response times for each endpoint (10 requests average)
  4. Memory and CPU usage
  5. Load test (100 requests to /hello-world)

5. Stop All Services

./stop-all.sh

Manual Docker Commands

Build Individual Images

docker-compose build golang
docker-compose build nodejs
docker-compose build nodejs-typescript
docker-compose build bun
docker-compose build deno

Start Individual Services

docker-compose up -d golang
docker-compose up -d nodejs
# etc.

View Logs

docker-compose logs -f golang
docker-compose logs -f nodejs
# etc.

Check Container Stats

docker stats

Example API Calls

Hello World

curl http://localhost:8081/hello-world

Echo

curl -X POST http://localhost:8081/echo \
  -H "Content-Type: application/json" \
  -d '{"message":"test"}'

Compute (Fibonacci)

curl http://localhost:8081/compute

Database Write

curl -X POST http://localhost:8081/db-write \
  -H "Content-Type: application/json" \
  -d '{"name":"Test Item","value":123}'

Database Read

curl http://localhost:8081/db-read

Performance Metrics

The benchmark script provides the following metrics:

  1. Image Size: Compressed and uncompressed Docker image sizes
  2. Cold Start Time: Time from container start to first successful response
  3. Response Time: Average, min, and max response times for each endpoint
  4. Memory Usage: Current memory consumption per container
  5. CPU Usage: CPU percentage per container
  6. Throughput: Requests per second under load

Database Configuration

PostgreSQL is configured with:

  • Host: postgres (via Docker network)
  • Port: 5432
  • Database: testdb
  • User: testuser
  • Password: testpass

The database is automatically initialized with a test_table containing sample data.

Notes

  • All implementations use optimized production builds
  • Multi-stage builds are used where applicable (Go, TypeScript)
  • Alpine Linux base images minimize size
  • Database connection retry logic ensures services start properly
  • All endpoints implement consistent error handling

Accounts Payable Implementations

In addition to the basic endpoint comparisons, this repository includes three production-grade Accounts Payable implementations for real-world application benchmarking:

1. golang-mongo - Go + MongoDB (Raw Driver)

  • Pure Go with official MongoDB driver
  • Port: 8080 (app), 27017 (MongoDB)
  • Features: Manual transactions, optimistic locking, production error handling

2. golang-mongo-orm - Go + MongoDB + MGM ORM

  • Go with MGM (Mongo Go Models) ORM
  • Port: 8081 (app), 27018 (MongoDB)
  • Features: ORM benefits, automatic timestamps, cleaner code

3. nodejs-express-mongo - Node.js + Express + Mongoose

  • Node.js with Express and Mongoose ODM
  • Port: 8082 (app), 27019 (MongoDB)
  • Features: Schema validation, middleware hooks, rapid development

All three implementations include:

  • Complete vendor management (CRUD)
  • Full invoice lifecycle (draft → approved → paid)
  • MongoDB transactions for payment processing
  • Production-grade error handling and validation
  • Business logic enforcement
  • Graceful shutdown and health checks

Quick Start for AP Implementations:

# See detailed guides
cat ACCOUNTS_PAYABLE.md      # Implementation comparison
cat QUICKSTART_AP.md          # Quick start guide

# Run individual implementation
cd golang-mongo && docker-compose up --build
cd golang-mongo-orm && docker-compose up --build
cd nodejs-express-mongo && docker-compose up --build

Cleaning Up

Basic Implementations

Remove all containers and volumes:

docker-compose down -v

Remove all images:

docker-compose down --rmi all -v

Accounts Payable Implementations

# Stop and remove all AP implementations
docker-compose -f golang-mongo/docker-compose.yml down -v
docker-compose -f golang-mongo-orm/docker-compose.yml down -v
docker-compose -f nodejs-express-mongo/docker-compose.yml down -v

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published