Debugging High Disk Write Throughput (5-6MB/s) in CakePHP on Gentoo Linux


2 views

When your Gentoo server running CakePHP shows constant 5-6MB/s disk writes with severe performance degradation, we're likely looking at either:

  1. Application-level logging gone wild
  2. Database transaction issues
  3. Filesystem/cache misconfiguration
  4. Background processes writing excessively

First, identify the processes causing I/O pressure:

# Real-time I/O monitoring
iotop -oP

# Alternative using /proc
watch -n 1 "cat /proc/diskstats | grep -E 'sd[a-z] |vd[a-z]'"

# Find most active files
lsof +L1

Inspect these common CakePHP culprits:

# Check debug kit logs
ls -lah /path/to/app/tmp/logs/

# Verify model cache writes
find /path/to/app/tmp/cache/models/ -type f -printf '%T+ %p\n' | sort -r

# Database query logging
grep 'log' /path/to/app/config/app.php | grep -i true

For Gentoo specifically:

# Check portage tmp files
find /var/tmp/portage/ -mmin -5

# Verify kernel messages
dmesg | grep -i 'io scheduler'

# Analyze filesystem mount options
mount | grep ext4

If sessions are the issue, modify your CakePHP config:

// In config/app.php
'Session' => [
    'defaults' => 'cache',
    'handler' => [
        'config' => 'session_cache'
    ]
]

Then configure cache backend:

// In config/app.php
'Cache' => [
    'session_cache' => [
        'className' => 'Redis',
        'prefix' => 'myapp_sess_',
        'host' => '127.0.0.1',
        'port' => 6379,
        'timeout' => 0.2
    ]
]

For deeper analysis on Gentoo:

# Install systemtap if needed
emerge -a dev-util/systemtap

# Basic write tracing script
stap -e 'probe vfs.write {
    printf("%s %d %s %d\\n", execname(), pid(), filename, $count)
}'
  • Verify tmpfs usage for /tmp and /run
  • Check PHP opcache configuration
  • Review CakePHP core cache configurations
  • Consider mounting /var/tmp/portage as tmpfs during builds

When dealing with mysterious disk I/O bottlenecks on Linux, these commands should be your first responders:


# Real-time disk activity (install if missing)
sudo apt-get install iotop   # Debian/Ubuntu
sudo emerge --ask sys-process/iotop  # Gentoo

# Run as root:
sudo iotop -oPa

# Alternative: kernel-based monitoring
sudo cat /proc/diskstats

For CakePHP applications specifically, check these common write-heavy operations:


# 1. DebugKit logs (can explode during development)
ls -lh /app/tmp/debug_kit/

# 2. Session handling (file-based by default)
grep 'Session.save' /app/config/app.php
find /tmp -name "sess_*" -exec ls -lh {} +

# 3. Cache writes
find /app/tmp/cache/ -type f -print0 | xargs -0 ls -lh

For deeper analysis on Gentoo, SystemTap provides surgical precision:


# Install SystemTap kernel modules
sudo emerge --ask dev-util/systemtap

# Basic write tracing script (save as trace_writes.stp):
probe kernel.function("vfs_write") {
    printf("%s %d %s\n", execname(), pid(), filename)
}

# Run with:
sudo stap trace_writes.stp

MySQL/MariaDB often contribute to disk writes unexpectedly:


# Check InnoDB write patterns
SHOW ENGINE INNODB STATUS\G
SHOW GLOBAL STATUS LIKE 'Innodb_%write%';

# Temporary table writes
SHOW GLOBAL STATUS LIKE 'Created_tmp%';

While investigating, these can provide immediate relief:


# Move tmpfs for session/cache
sudo mount -t tmpfs -o size=512M tmpfs /app/tmp/cache/

# Limit logging (temporarily)
sudo sysctl -w vm.dirty_bytes=536870912  # 512MB buffer
sudo sysctl -w vm.dirty_background_bytes=268435456