Overview
The TailStack install scripts (install.ps1 and install.sh) are production-grade orchestration utilities that manage parallel PNPM installations across your entire monorepo. Unlike simple pnpm install -r, these scripts intelligently monitor system resources and dynamically adjust concurrency to prevent system crashes.
Key Features
Smart Parallelization
Dynamically adjusts concurrent installations based on real-time CPU and RAM usage
Load Monitoring
Continuously monitors system metrics to prevent resource exhaustion
Automatic Throttling
Suspends jobs when system load exceeds thresholds, resumes when safe
State Machine Architecture
Robust RUNNING/PAUSED state management with hysteresis loops
How It Works
System Architecture
The install script implements a sophisticated orchestration loop:Three-State System
- RUNNING State
- PAUSED State
- COMPLETED State
Active Processing Mode
- Spawns new jobs based on available resources
- Dynamic concurrency:
Floor(Cores × (1 - CPU/100)) - Minimum 1 job, maximum = logical cores
- Monitors RAM: pauses if < 500MB free
- → PAUSED when CPU or RAM exceeds 90%
Usage
- PowerShell
- Shell
Requirements:
- PowerShell 5.1+ (Windows) or PowerShell Core 7+ (cross-platform)
- PNPM installed and in PATH
- Windows: CIM/WMI access for system monitoring
Load Monitoring System
Metrics Collection
The script monitors two critical metrics:CPU Usage
Measurement:
- Windows:
Win32_Processor.LoadPercentagevia CIM - Linux/macOS:
/proc/statdelta calculation
RAM Usage
Measurement:
- Windows:
Win32_OperatingSystemmemory counters - Linux:
/proc/meminfoMemAvailable - macOS:
vm_statequivalent
Threshold System
Critical Threshold (90%)
Critical Threshold (90%)
Triggers: System enters PAUSED stateActions:
- All running jobs receive suspend signal
- No new jobs spawn
- Dashboard shows “PAUSED” status
Safe Threshold (75%)
Safe Threshold (75%)
Triggers: System returns to RUNNING stateActions:
- All suspended jobs receive resume signal
- New jobs can spawn based on dynamic limits
- Dashboard shows “RUNNING” status
Dynamic Concurrency
Dynamic Concurrency
Formula:Example (8-core system):
- CPU at 20% → 8 × 0.80 = 6 concurrent jobs
- CPU at 50% → 8 × 0.50 = 4 concurrent jobs
- CPU at 80% → 8 × 0.20 = 1 concurrent job
Output Examples
- Normal Operation
- High Load Scenario
- Completion Summary
Advanced Features
Job Suspension (Process Control)
- Windows Implementation
- Unix Implementation
C# Interop with kernel32.dllPowerShell Usage:
Native Thread Control
Windows implementation suspends individual threads, preserving process state perfectly. Memory remains allocated but CPU consumption drops to zero.
Crash Prevention
The TailStack install scripts solve these issues:- ✅ Dynamic concurrency based on actual load
- ✅ Automatic throttling prevents resource exhaustion
- ✅ Job suspension instead of termination
- ✅ Progress preservation during pauses
- ✅ Predictable behavior with state machine
Performance Characteristics
Execution Speed
Execution Speed
Typical Performance (vs sequential):
Factors affecting speed:
| Packages | Sequential | Parallel Script | Speedup |
|---|---|---|---|
| 5-10 | 2-5 min | 30-60 sec | 3-5× |
| 10-30 | 5-15 min | 1-3 min | 4-6× |
| 30-100 | 15-45 min | 3-8 min | 5-7× |
- Network latency (package downloads)
- Shared dependencies (PNPM store hits)
- System specs (CPU cores, RAM, disk I/O)
- Background load (other applications)
Resource Consumption
Resource Consumption
CPU Usage:
- Startup: 20-40% (scanning phase)
- Active: 60-90% (installation phase)
- Throttled: 40-60% (dynamic adjustment)
- PAUSED: 10-20% (monitoring only)
- Per job: 100-300 MB average
- Concurrent jobs: 1-3 GB total
- Safety margin: 500 MB minimum free
- Peak: Typically 60-80% of total RAM
Scalability
Scalability
System Requirements:
The script automatically adapts to available resources.
| Monorepo Size | Min RAM | Min CPU | Recommended |
|---|---|---|---|
| Small (5-10) | 4 GB | 2 cores | 8 GB, 4 cores |
| Medium (30) | 8 GB | 4 cores | 16 GB, 8 cores |
| Large (100+) | 16 GB | 8 cores | 32 GB, 16 cores |
Troubleshooting
Installation Failures
Installation Failures
Check Summary Output:Common Causes:
- Network errors: Retry or check firewall
- Peer dependency conflicts: Check package.json
- Insufficient disk space: Clear PNPM store
- Corrupted cache: Run clean script first
Script Hangs or Freezes
Script Hangs or Freezes
Symptoms:2. Force termination:
- Dashboard stops updating
- Progress stuck at same percentage
- System responsive but script unresponsive
PNPM Not Found Error
PNPM Not Found Error
Error Message:Solutions:Install PNPM globally:Verify installation:Add to PATH (if needed):
Permission Errors
Permission Errors
Windows:Linux/macOS:
Best Practices
Close Resource-Heavy Apps
Free up system resources before installation:
- Close browsers with many tabs
- Pause video streaming
- Exit Docker containers
- Stop development servers
Monitor First Run
Watch the dashboard during first run to understand system behavior:
- Note typical CPU/RAM usage
- Observe pause/resume cycles
- Check completion time as baseline
Technical Implementation
State Machine Logic
State Transitions (Pseudo-code)
Metrics Collection
Related Documentation
Clean Script
Learn about the cleanup utility that pairs with install
Custom Scripts
Create your own automation scripts for the monorepo
Monorepo Management
Understand PNPM workspaces and dependency management