feat: VPS load handling – rate limiting, session cleanup, Redis scaling, PM2 & Nginx#12
Draft
feat: VPS load handling – rate limiting, session cleanup, Redis scaling, PM2 & Nginx#12
Conversation
…dapter, PM2, Nginx Co-authored-by: SinghAman21 <155352431+SinghAman21@users.noreply.github.com> Agent-Logs-Url: https://github.com/GDGVITM/spectrum-game/sessions/8e62cc6c-99e5-4680-ad9c-874210499e98
Copilot created this pull request from a session on behalf of
SinghAman21
March 26, 2026 09:45
View session
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Single-process in-memory server with no cleanup or backpressure breaks under concurrent player load on a DigitalOcean VPS. This branch adds the infrastructure to handle it without changing game logic.
Server (
server/index.js)ATTACK_RATE_LIMIT). Drops excess events before they hit the queue, preventing memory exhaustion from flooding clients.SESSION_IDLE_MINUTES). Prevents unbounded RAM growth from abandoned games./healthendpoint – lightweight JSON response (uptime,sessions,sockets) for Nginx upstream checks and external monitors.SIGTERM/SIGINTdrains connections before exit; PM2 reload no longer drops live sockets.REDIS_URLto activate@socket.io/redis-adapter. Socket.io rooms then work correctly across all worker processes; omit it to stay single-process with zero new deps at runtime.Process management (
ecosystem.config.cjs)PM2 config that auto-selects mode based on environment:
fork/instances: 1whenREDIS_URLis absent (safe default)cluster/instances: maxwhenREDIS_URLis set (all CPU cores)Includes
max_memory_restart: 512M, rolling reload support, and merged log output.Reverse proxy (
nginx.conf)/health,/nimda,/socket.ioto Node; servesdist/staticallyUpgradeheaders,ip_hashsticky sessions for cluster mode (withhash $cookie_iodocumented as NAT-safe alternative)gzipon JS/CSS/JSON,Cache-Control: immutableon Vite hashed assetsConfig & docs
.env.example– all tunable variables (PORT,CORS_ORIGIN,NIMDA_PASSWORD,ATTACK_RATE_LIMIT,SESSION_IDLE_MINUTES,REDIS_URL)DEPLOYMENT.md– end-to-end DigitalOcean setup: Node/PM2/Nginx/Redis install, env wiring, PM2 startup persistence, Certbot HTTPS, UFW firewall ruleseslint.config.js– addsglobals.nodeoverride forserver/**to fix pre-existingprocessis-not-defined errors under the browser-scoped config