mirror of
https://github.com/DeNNiiInc/Website-Stress-Test.git
synced 2026-04-17 12:36:00 +00:00
Optimize for high concurrency: Node.js clustering, Web Workers, and system tuning
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# setup-server.sh - Initial Setup Script
|
||||
|
||||
# 1. Install Global Dependencies
|
||||
# 1. System Tuning for High Concurrency
|
||||
echo "Tuning system limits..."
|
||||
# Increase max open files for high connection counts
|
||||
if ! grep -q "soft nofile 65535" /etc/security/limits.conf; then
|
||||
echo "* soft nofile 65535" >> /etc/security/limits.conf
|
||||
echo "* hard nofile 65535" >> /etc/security/limits.conf
|
||||
fi
|
||||
# Apply limits to current session (for the rest of this script)
|
||||
ulimit -n 65535
|
||||
|
||||
# 2. Install Global Dependencies
|
||||
echo "Installing PM2..."
|
||||
npm install -g pm2
|
||||
|
||||
# 2. Clone Repository
|
||||
# Expects: REPO_URL, APP_DIR, GITHUB_TOKEN inside the script or env
|
||||
# We'll use arguments passed to this script: $1=REPO_URL $2=APP_DIR $3=GITHUB_TOKEN
|
||||
|
||||
# 3. Clone Repository
|
||||
# ... (rest of cloning logic)
|
||||
REPO_URL="$1"
|
||||
APP_DIR="$2"
|
||||
GITHUB_TOKEN="$3"
|
||||
|
||||
# Construct URL with token for auth
|
||||
# Extract host and path from REPO_URL (assuming https://github.com/user/repo.git)
|
||||
# We need to insert token: https://TOKEN@github.com/user/repo.git
|
||||
# Simple replacement:
|
||||
AUTH_REPO_URL="${REPO_URL/https:\/\//https:\/\/$GITHUB_TOKEN@}"
|
||||
|
||||
echo "Preparing application directory: $APP_DIR"
|
||||
@@ -33,18 +35,20 @@ else
|
||||
cd "$APP_DIR"
|
||||
fi
|
||||
|
||||
# 3. Install App Dependencies
|
||||
# 4. Install App Dependencies
|
||||
echo "Installing application dependencies..."
|
||||
npm install
|
||||
|
||||
# 4. Start Application with PM2
|
||||
# 5. Start Application with PM2
|
||||
APP_NAME="website-stress-test"
|
||||
echo "Starting application with PM2 ($APP_NAME)..."
|
||||
pm2 start proxy-server.js --name "$APP_NAME" --watch --ignore-watch="node_modules"
|
||||
# Using Node built-in clustering, but PM2 monitors the master
|
||||
pm2 stop "$APP_NAME" || true
|
||||
pm2 start proxy-server.js --name "$APP_NAME" --max-memory-restart 1G
|
||||
pm2 save
|
||||
pm2 startup | tail -n 1 | bash # Setup startup script
|
||||
|
||||
# 5. Setup Cron Job for Auto-Sync
|
||||
# 6. Setup Cron Job for Auto-Sync
|
||||
echo "Setting up Cron Job for auto-sync..."
|
||||
SCRIPT_PATH="$APP_DIR/auto-sync.sh"
|
||||
chmod +x "$SCRIPT_PATH"
|
||||
@@ -52,5 +56,5 @@ chmod +x "$SCRIPT_PATH"
|
||||
# Add to crontab if not exists
|
||||
(crontab -l 2>/dev/null; echo "*/5 * * * * $SCRIPT_PATH >> /var/log/app-sync.log 2>&1") | crontab -
|
||||
|
||||
echo "✅ Setup Complete! Application is running."
|
||||
echo "✅ Setup Complete! Application is running with system optimizations."
|
||||
pm2 status
|
||||
|
||||
Reference in New Issue
Block a user