Enhance run_optimized_192cores.sh to check for root privileges before setting process priority and CPU governor, providing user guidance for optimal performance.

This commit is contained in:
Alireza
2025-08-02 18:07:04 +03:30
parent 896831aa46
commit 6611207737
3 changed files with 225 additions and 4 deletions

View File

@@ -14,14 +14,26 @@ echo "⚙️ Configuring system for high-performance processing..."
echo "* Setting file descriptor limits..."
ulimit -n 65536
# Set process priority
# Set process priority (only if we have permission)
echo "* Setting process priority..."
renice -n -10 $$
if [ "$EUID" -eq 0 ]; then
renice -n -10 $$
echo "✅ Process priority set to -10"
else
echo "⚠️ Cannot set process priority (requires root privileges)"
echo "💡 Run with sudo for optimal performance"
fi
# Configure CPU governor for performance
# Configure CPU governor for performance (only if we have permission)
echo "* Configuring CPU governor..."
if command -v cpupower &> /dev/null; then
sudo cpupower frequency-set -g performance
if [ "$EUID" -eq 0 ]; then
cpupower frequency-set -g performance
echo "✅ CPU governor set to performance mode"
else
echo "⚠️ Cannot set CPU governor (requires root privileges)"
echo "💡 Run with sudo for optimal performance"
fi
fi
# Set environment variables for optimal performance

View File

@@ -0,0 +1,126 @@
#!/bin/bash
# Optimized setup script for 192-core processing (no root required)
# This script configures the system and runs the optimized processing pipeline
set -e
echo "🚀 Setting up optimized processing for 192 cores (no root required)..."
# System optimizations (user-level only)
echo "⚙️ Configuring system for high-performance processing..."
# Increase file descriptor limits (user-level)
echo "* Setting file descriptor limits..."
ulimit -n 65536
# Set process priority (user-level only)
echo "* Setting process priority..."
if [ "$EUID" -eq 0 ]; then
renice -n -10 $$
echo "✅ Process priority set to -10"
else
# Try to set a higher priority within user limits
renice -n 0 $$ 2>/dev/null || echo "⚠️ Cannot set process priority"
fi
# Configure CPU governor for performance (user-level check)
echo "* Checking CPU governor..."
if command -v cpupower &> /dev/null; then
if [ "$EUID" -eq 0 ]; then
cpupower frequency-set -g performance
echo "✅ CPU governor set to performance mode"
else
current_governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null || echo "unknown")
echo " Current CPU governor: $current_governor"
echo "💡 For optimal performance, run with sudo to set performance governor"
fi
fi
# Set environment variables for optimal performance
export PYTHONUNBUFFERED=1
export PYTHONOPTIMIZE=2
export OMP_NUM_THREADS=192
export MKL_NUM_THREADS=192
export OPENBLAS_NUM_THREADS=192
export VECLIB_MAXIMUM_THREADS=192
export NUMEXPR_NUM_THREADS=192
# Install optimized dependencies
echo "📦 Installing optimized dependencies..."
pip install -r requirements_optimized.txt
# Check if Vosk service is running
echo "🔍 Checking Vosk service status..."
if ! curl -s http://localhost:5000/ > /dev/null; then
echo "⚠️ Vosk service not running. Starting optimized service..."
# Start optimized Vosk service
cd ../vosk_service
# Make startup script executable
chmod +x start_with_deps.sh
# Choose between async and production mode
if [ "$USE_ASYNC" = "true" ]; then
export USE_ASYNC=true
./start_with_deps.sh &
VOSK_PID=$!
echo "✅ Vosk async service started with PID: $VOSK_PID"
else
# Use Gunicorn for production multiprocessing
export USE_GUNICORN=true
./start_with_deps.sh &
VOSK_PID=$!
echo "✅ Vosk Gunicorn service started with PID: $VOSK_PID"
fi
# Wait for service to be ready
echo "⏳ Waiting for service to be ready..."
for i in {1..30}; do
if curl -s http://localhost:5000/ > /dev/null; then
echo "✅ Service is ready!"
break
fi
sleep 1
done
else
echo "✅ Vosk service is already running"
fi
# Start performance monitoring in background
echo "📊 Starting performance monitoring..."
python monitor_performance.py &
MONITOR_PID=$!
echo "✅ Performance monitor started with PID: $MONITOR_PID"
# Function to cleanup on exit
cleanup() {
echo "🧹 Cleaning up..."
if [ ! -z "$VOSK_PID" ]; then
kill $VOSK_PID 2>/dev/null || true
fi
if [ ! -z "$MONITOR_PID" ]; then
kill $MONITOR_PID 2>/dev/null || true
fi
echo "✅ Cleanup complete"
}
# Set trap to cleanup on script exit
trap cleanup EXIT
# Run the optimized processing
echo "🎯 Starting optimized processing with 192 cores..."
echo "📊 Configuration:"
echo " - CPU cores: 192"
echo " - Batch size: 32"
echo " - Max concurrent requests: 48"
echo " - Process pool workers: 192"
echo ""
# Run the optimized script
python batch_confirm_hf_optimized.py
echo "✅ Processing complete!"
echo "📈 Check performance_plot.png for detailed performance analysis"
echo "📊 Check performance_log.json for raw performance data"

View File

@@ -0,0 +1,83 @@
#!/bin/bash
# Simple optimized processing script (no root required)
# Focuses on Python-level optimizations for 192 cores
set -e
echo "🚀 Starting optimized processing for 192 cores..."
# Set environment variables for optimal performance
export PYTHONUNBUFFERED=1
export PYTHONOPTIMIZE=2
export OMP_NUM_THREADS=192
export MKL_NUM_THREADS=192
export OPENBLAS_NUM_THREADS=192
export VECLIB_MAXIMUM_THREADS=192
export NUMEXPR_NUM_THREADS=192
# Install dependencies if needed
echo "📦 Installing dependencies..."
pip install -r requirements_optimized.txt
# Check if Vosk service is running
echo "🔍 Checking Vosk service status..."
if ! curl -s http://localhost:5000/ > /dev/null; then
echo "⚠️ Vosk service not running. Starting service..."
# Start Vosk service
cd ../vosk_service
chmod +x start_with_deps.sh
./start_with_deps.sh &
VOSK_PID=$!
echo "✅ Vosk service started with PID: $VOSK_PID"
# Wait for service to be ready
echo "⏳ Waiting for service to be ready..."
for i in {1..30}; do
if curl -s http://localhost:5000/ > /dev/null; then
echo "✅ Service is ready!"
break
fi
sleep 1
done
else
echo "✅ Vosk service is already running"
fi
# Start performance monitoring
echo "📊 Starting performance monitoring..."
python monitor_performance.py &
MONITOR_PID=$!
echo "✅ Performance monitor started with PID: $MONITOR_PID"
# Function to cleanup on exit
cleanup() {
echo "🧹 Cleaning up..."
if [ ! -z "$VOSK_PID" ]; then
kill $VOSK_PID 2>/dev/null || true
fi
if [ ! -z "$MONITOR_PID" ]; then
kill $MONITOR_PID 2>/dev/null || true
fi
echo "✅ Cleanup complete"
}
# Set trap to cleanup on script exit
trap cleanup EXIT
# Run the optimized processing
echo "🎯 Starting optimized processing with 192 cores..."
echo "📊 Configuration:"
echo " - CPU cores: 192"
echo " - Batch size: 32"
echo " - Max concurrent requests: 48"
echo " - Process pool workers: 192"
echo ""
# Run the optimized script
python batch_confirm_hf_optimized.py
echo "✅ Processing complete!"
echo "📈 Check performance_plot.png for detailed performance analysis"
echo "📊 Check performance_log.json for raw performance data"