Optimizing Apache/MySQL/PHP Memory Usage on Solaris Web Servers (256MB RSS Limit)


1 views

When facing memory constraints on Solaris servers running LAMP stacks, the first step is identifying memory hogs. For Solaris specifically, these commands provide crucial insights:


# Show overall memory usage
prstat -Z -s cpu

# Detailed process memory (replace pid)
pmap -x [PID]

# MySQL memory usage
mysqladmin variables | grep -i buffer

Apache's prefork MPM is notorious for memory consumption. Consider these adjustments in httpd.conf:


# Reduce MaxClients (default is often 256 - way too high for 256MB RAM)
MaxClients 20
ServerLimit 20

# Lower KeepAlive settings
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 2

# Disable unused modules (example)
LoadModule negotiation_module modules/mod_negotiation.so

PHP can leak memory through extensions and misconfigured limits:


; php.ini optimizations
memory_limit = 32M
max_execution_time = 30
realpath_cache_size = 64k
opcache.memory_consumption = 16

Default MySQL configs assume dedicated servers. For 256MB systems:


# my.cnf adjustments
[mysqld]
key_buffer_size = 16M
query_cache_size = 8M
tmp_table_size = 8M
max_connections = 20
table_open_cache = 64

Leverage Solaris features for better memory management:


# Create a dedicated memory cap for your zone
zonecfg -z [zonename] add capped-memory
zonecfg -z [zonename] set physical=256M
zonecfg -z [zonename] set swap=512M

# Monitor with Solaris-specific tools
vmstat -p 5
kstat -n system_pages

When Apache proves too heavy for the memory constraints:


# Lighttpd minimal config example
server.modules = ("mod_access", "mod_rewrite")
server.document-root = "/var/www"
server.max-connections = 30
server.max-keep-alive-requests = 10

Remember to benchmark after each change using tools like ab or siege to verify performance hasn't degraded significantly.


When your Solaris box shows 411M RSS and 721M swap usage with just Apache+MySQL+PHP, we're looking at classic memory bloat. First, verify actual usage with:

prstat -Z -s rss
vmstat 5 4
swap -s

For memory-constrained Apache installations, these httpd.conf tweaks are lifesavers:

# Reduce MaxRequestWorkers (Apache 2.4+) or MaxClients (2.2)
MaxRequestWorkers 20

# Limit modules to ESSENTIALS only
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

# Aggressive keepalive settings
KeepAlive Off
MaxKeepAliveRequests 0

These php.ini settings reduced memory usage by 40% in my last Solaris deployment:

memory_limit = 32M
realpath_cache_size = 128k
opcache.memory_consumption = 32
opcache.interned_strings_buffer = 8

A minimal my.cnf for 256MB systems:

[mysqld]
key_buffer_size = 16M
query_cache_size = 8M
tmp_table_size = 8M
innodb_buffer_pool_size = 64M
table_open_cache = 128

Don't overlook these Solaris-specific tweaks:

# Limit process memory with rlimits
prctl -n process.max-address-space -t privileged -v 512M -i process $$

# Adjust priority of database processes
priocntl -s -c FX -p 0 -i pid $(pgrep mysqld)

  • Replace Apache with lighttpd for static content
  • Implement PHP opcache with file validation
  • Convert MyISAM tables to InnoDB where possible
  • Set Expires headers for static assets
  • Disable unused PECL extensions