ΰΈ£ΰΈ°ΰΈΰΈΰΈΰΈ£ΰΈ±ΰΈΰΉΰΈΰΉΰΈΰΈΰΈ£ΰΈ°ΰΈͺΰΈ΄ΰΈΰΈΰΈ΄ΰΈ ΰΈ²ΰΈΰΈ£ΰΈ°ΰΈΰΈ±ΰΈΰΈ«ΰΈ₯ΰΈ²ΰΈ’ΰΈ₯ΰΉΰΈ²ΰΈΰΈΰΈΰΈ₯ΰΈ₯ΰΉΰΈ²
ΰΉΰΈΰΉΰΈ²ΰΈ«ΰΈ‘ΰΈ²ΰΈ’: ΰΈ£ΰΈΰΈΰΈ£ΰΈ±ΰΈΰΈΰΈΉΰΉΰΉΰΈΰΉΰΈΰΈ²ΰΈ 10,000+ ΰΈΰΈΰΈΰΈ£ΰΉΰΈΰΈ‘ΰΈΰΈ±ΰΈ ΰΈΰΉΰΈ§ΰΈ’ Response Time < 200ms
| Phase | Features | Expected Gain | Time to Implement |
|---|---|---|---|
| Phase 1 | Database Indexes + Redis | +50% Capacity | 30 minutes |
| Phase 2 | Laravel Octane/Swoole | +200-300% Performance | 1-2 hours |
| Phase 3 | Horizontal Scaling | Support 10,000+ Users | 4-8 hours |
Expected Improvement: +50% capacity increase Implementation Time: 30 minutes
- β Analytics table indexes (vendor_analytics, vendor_store_visits)
- β E-commerce table indexes (orders, products)
- β Store lookup indexes (vendor_stores)
- β User & session indexes
- β Wallet & transaction indexes
# Step 1: Run the index migration
php artisan migrate --path=database/migrations/2025_11_10_000001_add_performance_indexes.php
# Step 2: Verify indexes were created
php artisan db:show
# Expected output: ~30+ new indexes created- Analytics queries: 5x faster
- Order queries: 4x faster
- Product listing: 3x faster
- Session lookups: 6x faster
- 10-100x faster than file-based cache
- Support for cache tagging
- Persistent storage option
- Pub/Sub capabilities
Step 1: Install Redis
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install redis-server
# macOS
brew install redis
# Start Redis
sudo systemctl start redis
# or
redis-serverStep 2: Install PHP Redis Extension
# Ubuntu/Debian
sudo apt-get install php-redis
# macOS
pecl install redis
# Verify installation
php -m | grep redisStep 3: Update .env
# Cache Configuration
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis
# Redis Configuration
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_DB=0
REDIS_CACHE_DB=1
REDIS_PREFIX=thaiprompt_
# Optional: Redis Cluster
REDIS_CLUSTER=falseStep 4: Clear and Warm Cache
# Clear old cache
php artisan cache:clear
php artisan config:clear
# Warm up new cache
php artisan config:cache
php artisan route:cache
php artisan view:cacheStep 5: Test Redis Connection
# Test Redis
php artisan tinker
# Run this in tinker:
>>> Cache::put('test', 'Redis is working!', 60);
>>> Cache::get('test');
# Should return: "Redis is working!"- Cache hits: 50-100x faster
- Session read/write: 10x faster
- Queue processing: 5x faster
- Overall response time: -40% reduction
Expected Improvement: +200-300% performance boost Implementation Time: 1-2 hours
Laravel Octane keeps your application in memory, eliminating the boot time for each request.
Traditional Laravel Request:
Request β Boot Laravel β Process β Shutdown β Response
Time: ~150-300ms
Laravel Octane Request:
Request β Process (Laravel already in memory) β Response
Time: ~20-50ms (6-10x faster!)
Step 1: Install Octane
# Install Laravel Octane
composer require laravel/octane
# Publish Octane configuration
php artisan octane:install
# Choose: [1] Swoole (recommended)Step 2: Install Swoole
# Ubuntu/Debian
sudo apt-get install php-swoole
# macOS
pecl install swoole
# Verify installation
php --ri swooleStep 3: Update .env
# Octane Configuration
OCTANE_SERVER=swoole
OCTANE_HOST=127.0.0.1
OCTANE_PORT=8000
OCTANE_WORKERS=4
OCTANE_TASK_WORKERS=4
OCTANE_MAX_REQUEST=10000Step 4: Start Octane
# Development
php artisan octane:start
# Production (with auto-reload)
php artisan octane:start --workers=4 --task-workers=4 --max-requests=10000
# With Supervisor (recommended for production)
# See supervisor configuration belowStep 5: Supervisor Configuration
Create /etc/supervisor/conf.d/octane.conf:
[program:octane]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/your/project/artisan octane:start --server=swoole --host=127.0.0.1 --port=8000 --workers=4 --task-workers=4
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/log/octane.log
stopwaitsecs=3600Reload Supervisor:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start octane:*Step 6: Nginx Configuration
Update your Nginx config to proxy to Octane:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Important Services to Warm:
Edit config/octane.php:
'warm' => [
'config',
'routes',
'views',
],
'tables' => [
'roles',
'permissions',
'settings',
],Memory Leak Prevention:
# Restart Octane workers periodically
php artisan octane:reload
# Or set max requests per worker
OCTANE_MAX_REQUEST=10000- Response time: 6-10x faster (50ms vs 300ms)
- Throughput: 3-4x more requests/second
- Memory usage: More efficient (shared memory)
- Boot time: Eliminated (app stays in memory)
Expected Improvement: Support 10,000+ concurrent users Implementation Time: 4-8 hours
βββββββββββββββββββ
β Load Balancer β
β (Nginx/HAProxy)β
ββββββββββ¬βββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββ
βΌ βΌ βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β App Server 1β β App Server 2β β App Server Nβ
β (Octane) β β (Octane) β β (Octane) β
ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββ¬ββββββββ
β β β
βββββββββββββββββββββ΄ββββββββββββββββββββ
β
ββββββββββββββ΄βββββββββββββ
βΌ βΌ
βββββββββββββββ βββββββββββββββ
β Redis β β MySQL β
β (Cache) β β (Primary) β
βββββββββββββββ ββββββββ¬βββββββ
β
ββββββββββββββ΄βββββββββββββ
βΌ βΌ
βββββββββββββββ βββββββββββββββ
β MySQL β β MySQL β
β (Replica 1)β β (Replica 2)β
βββββββββββββββ βββββββββββββββ
Create /etc/nginx/sites-available/load-balancer.conf:
upstream app_servers {
# Load balancing algorithm
least_conn; # or: ip_hash, round_robin
# App servers
server 192.168.1.101:8000 weight=1 max_fails=3 fail_timeout=30s;
server 192.168.1.102:8000 weight=1 max_fails=3 fail_timeout=30s;
server 192.168.1.103:8000 weight=1 max_fails=3 fail_timeout=30s;
# Backup server
server 192.168.1.104:8000 backup;
# Health check
keepalive 32;
}
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://app_servers;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Timeouts
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
# Buffers
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
}
# Health check endpoint
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}Master Database (Write):
Edit my.cnf on master:
[mysqld]
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = thaipromptReplica Database (Read):
Edit my.cnf on replica:
[mysqld]
server-id = 2
relay-log = /var/log/mysql/relay-bin
log_bin = /var/log/mysql/mysql-bin.log
read_only = 1Laravel Configuration:
Update config/database.php:
'mysql' => [
'read' => [
'host' => [
'192.168.1.201', // Replica 1
'192.168.1.202', // Replica 2
],
],
'write' => [
'host' => ['192.168.1.200'], // Master
],
'driver' => 'mysql',
'database' => env('DB_DATABASE', 'thaiprompt'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],Install Redis Cluster:
# Create 6 Redis nodes (minimum 3 master + 3 slave)
# See detailed guide: https://redis.io/topics/cluster-tutorialUpdate .env:
REDIS_CLUSTER=true
REDIS_CLUSTERS=redis-node1:6379,redis-node2:6379,redis-node3:6379Update config/session.php:
'driver' => env('SESSION_DRIVER', 'redis'),
'connection' => 'session',All app servers must use Redis for sessions!
- Concurrent users: 10,000+ simultaneous
- Failover: Automatic (if one server fails)
- Scalability: Horizontal (add more servers)
- High availability: 99.9%+ uptime
Access at: /seller/analytics/system-monitoring
Features:
- π₯οΈ CPU Usage - Real-time graph (60 seconds history)
- πΎ Memory Usage - Live monitoring with alerts
- π Active Connections - Sessions + Database
- πΏ Disk Usage - Storage monitoring
- π Database Metrics - Size, queries/sec
- β‘ Cache Status - Hit rate, memory usage
Auto-refresh: Every 2 seconds
Run benchmarks to measure improvements:
# Install Apache Bench
sudo apt-get install apache2-utils
# Test current performance
ab -n 1000 -c 100 http://your-domain.com/
# After Phase 1 (expect: +50% requests/sec)
ab -n 1000 -c 100 http://your-domain.com/
# After Phase 2 (expect: +200-300% requests/sec)
ab -n 1000 -c 100 http://your-domain.com/
# After Phase 3 (expect: handle 10,000+ concurrent)
ab -n 10000 -c 1000 http://your-domain.com/- Run database index migration
- Install Redis server
- Install PHP Redis extension
- Update .env with Redis configuration
- Clear and warm cache
- Test Redis connection
- Run performance benchmarks
- Monitor system metrics
- Install Laravel Octane
- Install Swoole extension
- Configure Octane settings
- Setup Supervisor for Octane
- Update Nginx to proxy to Octane
- Test Octane server
- Monitor memory usage
- Run performance benchmarks
- Setup additional app servers
- Configure load balancer
- Setup MySQL read replicas
- Configure Redis cluster
- Update Laravel database config
- Test failover scenarios
- Monitor all servers
- Run stress tests
| Metric | Before | After Phase 1 | After Phase 2 | After Phase 3 |
|---|---|---|---|---|
| Response Time | 300ms | 180ms | 50ms | 30ms |
| Requests/sec | 100 | 150 | 400-500 | 1,000+ |
| Concurrent Users | 500 | 750 | 2,000 | 10,000+ |
| Cache Hit Rate | 60% | 90% | 95% | 98% |
| Database Query Time | 100ms | 20ms | 15ms | 10ms |
| Memory Usage | High | Medium | Optimized | Distributed |
| Uptime | 99% | 99.5% | 99.9% | 99.99% |
# Check Redis is running
redis-cli ping
# Should return: PONG
# Check Redis memory
redis-cli info memory
# Monitor Redis commands
redis-cli monitor# Check Octane logs
tail -f /var/log/octane.log
# Reload Octane workers
php artisan octane:reload
# Stop and restart
php artisan octane:stop
php artisan octane:start# Check Nginx status
sudo systemctl status nginx
# Test Nginx config
sudo nginx -t
# View error logs
tail -f /var/log/nginx/error.logΰΈ£ΰΈ°ΰΈΰΈΰΈΰΈΰΈΰΈΰΈΈΰΈΰΈΰΈ£ΰΉΰΈΰΈ‘ΰΈ£ΰΈΰΈΰΈ£ΰΈ±ΰΈΰΈΰΈΉΰΉΰΉΰΈΰΉΰΈΰΈ²ΰΈΰΈ£ΰΈ°ΰΈΰΈ±ΰΈΰΈ«ΰΈ₯ΰΈ²ΰΈ’ΰΈ₯ΰΉΰΈ²ΰΈΰΈΰΈΰΈ₯ΰΈ₯ΰΉΰΈ²ΰΉΰΈ₯ΰΉΰΈ§!
Next Steps:
- β Deploy Phase 1 (30 minutes) β +50% capacity
- π Deploy Phase 2 (1-2 hours) β 3-4x performance
- π Deploy Phase 3 (4-8 hours) β 10,000+ users
Support: ΰΈͺΰΈ³ΰΈ«ΰΈ£ΰΈ±ΰΈΰΈΰΈ³ΰΈΰΈ²ΰΈ‘ΰΉΰΈΰΈ΄ΰΉΰΈ‘ΰΉΰΈΰΈ΄ΰΈ‘ ΰΈΰΈ£ΰΈΈΰΈΰΈ²ΰΈΰΈ΄ΰΈΰΈΰΉΰΈΰΈΰΈ΅ΰΈ‘ΰΈΰΈ±ΰΈΰΈΰΈ²