God Mode: Docker Optimizations for 100k Scale (Memory, Ulimits, Threadpool)
This commit is contained in:
27
Dockerfile
27
Dockerfile
@@ -1,17 +1,17 @@
|
||||
# God Mode (Valhalla) Dockerfile
|
||||
# Optimized for reliable builds with full dependencies
|
||||
# Optimized for "Insane Mode" (High Concurrency & Throughput)
|
||||
|
||||
# 1. Base Image
|
||||
FROM node:20-alpine AS base
|
||||
WORKDIR /app
|
||||
# Install libc6-compat for sharp/performance
|
||||
RUN apk add --no-cache libc6-compat
|
||||
# Install system utilities for performance tuning
|
||||
RUN apk add --no-cache libc6-compat curl bash
|
||||
|
||||
# 2. Dependencies
|
||||
FROM base AS deps
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json* ./
|
||||
# Use npm install for robustness (npm ci can fail if lockfile is out of sync)
|
||||
# Install deps (Legacy Peer Deps for Astro ecosystem compatibility)
|
||||
RUN npm install --legacy-peer-deps
|
||||
|
||||
# 3. Builder
|
||||
@@ -19,24 +19,39 @@ FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# 4. Runner
|
||||
# 4. Runner (God Mode Runtime)
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=4321
|
||||
|
||||
# Create non-root user
|
||||
# --- GOD MODE OPTIMIZATIONS ---
|
||||
# 1. Memory: Allow up to 16GB RAM usage (Prevents GC thrashing on 100k items)
|
||||
ENV NODE_OPTIONS="--max-old-space-size=16384"
|
||||
# 2. Threadpool: Increase libuv pool for heavy database I/O (Default 4 -> 128)
|
||||
ENV UV_THREADPOOL_SIZE=128
|
||||
# 3. Timeouts: Increase default timeouts for long-running batch jobs
|
||||
ENV HTTP_TIMEOUT=300000
|
||||
ENV KEEP_ALIVE_TIMEOUT=300000
|
||||
|
||||
# Create dedicated runner user
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 astro
|
||||
|
||||
# Copy artifacts
|
||||
COPY --from=builder /app/dist ./dist
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY package.json ./
|
||||
|
||||
# Security & Permissions
|
||||
USER astro
|
||||
|
||||
# Expose Port
|
||||
EXPOSE 4321
|
||||
|
||||
# Launch with optimized settings
|
||||
CMD ["node", "./dist/server/entry.mjs"]
|
||||
|
||||
28
docker-compose.yml
Normal file
28
docker-compose.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
god-mode:
|
||||
build: .
|
||||
restart: always
|
||||
ports:
|
||||
- "4321:4321"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DATABASE_URL=${DATABASE_URL}
|
||||
- REDIS_URL=${REDIS_URL}
|
||||
- GOD_MODE_TOKEN=${GOD_MODE_TOKEN}
|
||||
# GOD MODE LIMITS:
|
||||
ulimits:
|
||||
nofile:
|
||||
soft: 65536
|
||||
hard: 65536
|
||||
nproc: 65536
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 16G
|
||||
cpus: '8.0'
|
||||
logging:
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
Reference in New Issue
Block a user