Preloader
Server Maintenance

Xtream UI High Memory Usage Solution

A practical step-by-step guide to stop your server from running out of RAM.


The Usual Suspects

Most "mystery" RAM spikes in Xtream UI are caused by one of four things: bloated database log tables, an oversized MariaDB buffer pool, PHP-FPM workers not recycling, or uncapped Redis instances. This guide addresses each one.

1Step 1: Safety & Diagnosis

Before deleting anything, take a database backup. If you make a mistake, you can restore it.

mysqldump --single-transaction --quick --lock-tables=false xtream_iptvpro > /root/xtream_iptvpro_backup.sql

Next, identify what is actually eating your RAM. Don't guess.

ps aux --sort=-rss | head -n 30

Look for mariadbd (Database), php-fpm (Web Workers), or ffmpeg.

2Step 2: Clean Bloated Log Tables

Xtream UI accumulates massive logs. Clearing these is often the fastest win for performance.

Option A: Aggressive Cleanup (Truncate)
Warning: This deletes all historical logs.

mysql -e "USE xtream_iptvpro; TRUNCATE TABLE client_logs;" mysql -e "USE xtream_iptvpro; TRUNCATE TABLE user_activity;" mysql -e "USE xtream_iptvpro; TRUNCATE TABLE mag_logs;"

Option B: Gentle Cleanup (Delete old rows)
Keeps recent data (e.g., last 3 days).

mysql -e "USE xtream_iptvpro; DELETE FROM user_activity WHERE date < UNIX_TIMESTAMP(NOW() - INTERVAL 3 DAY);" mysql -e "USE xtream_iptvpro; DELETE FROM client_logs WHERE date < UNIX_TIMESTAMP(NOW() - INTERVAL 3 DAY);"

3Step 3: Tune MariaDB Memory

By default, MariaDB might try to use too much RAM for caching (InnoDB Buffer Pool). On a server running everything (Main + Streams), this starves other processes.

Edit your MariaDB config:

nano /etc/mysql/mariadb.conf.d/50-server.cnf # OR nano /etc/mysql/my.cnf

Find [mysqld] and set a sane value. For example, on a 16GB server, limit it to 2GB:

innodb_buffer_pool_size = 2G

Restart MariaDB: systemctl restart mariadb

4Step 4: Tune PHP-FPM

PHP workers can "leak" memory over time. We need to force them to recycle.

Edit your pool config (e.g., /etc/php/7.4/fpm/pool.d/www.conf):

pm = dynamic pm.max_children = 20 ; Adjust based on your RAM pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 10 ; Critical setting to fix leaks pm.max_requests = 500

This restarts every worker after 500 requests, freeing up any accumulated memory.

5Step 5: Cap Redis Memory

If you use Redis, it can grow indefinitely. Set a hard limit.

nano /etc/redis/redis.conf

Add or uncomment:

maxmemory 512mb maxmemory-policy allkeys-lru

Restart Redis: systemctl restart redis

6Step 6: Add Swap (Safety Net)

Swap acts as an overflow buffer. It prevents your server from crashing hard (OOM Kill) if RAM runs out momentarily.

fallocate -l 2G /swapfile chmod 600 /swapfile mkswap /swapfile swapon /swapfile echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab

7Step 7: Validation

After applying these fixes, monitor your server. Run free -h to check memory usage and ensure Swap is active but barely used. If RAM still climbs over days, consider lowering pm.max_children or the innodb_buffer_pool_size further.