brett@3riverdev.com 260.349.5732

Apache and MariaDB/MySQL Settings for Low-Memory Servers

Posted on June 6 , 2015

Gone are the days of requiring large amounts of resources to adequately run a fast, enterprise-grade web server.  I currently run a single DigitalOcean instance (the 1GB memory plan) and host many web platforms with no performance issues, whatsoever.  I thought I’d share the settings that have been working really well in this low-memory environment.  Note that the server is running CentOS 7, but these settings should be applicable for any OS.

For what it’s worth, if you’re interested in a DigitalOcean account, click here to use my referral — you’ll gain $10 in credits when you sign up…

Apache (/etc/httpd/conf/httpd.conf)

The 15 ‘MaxClients’ was defined empirically.  It’s the highest value I’ve been able to use and not run into out-of-memory issues.  Some users may be able to get closer to 20 or more, but 15 has been chugging along for months without any problems.

...
StartServers 1
MinSpareServers 1
MaxSpareServers 5
MaxClients 15
MaxRequestsPerChild 300
KeepAliveTimeout 3
HostnameLookups Off
...

MariaDB/MySQL (/etc/my.conf)

...
key_buffer = 16K
max_allowed_packet = 1M
table_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K

skip-bdb

innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout
...

If you use MyISAM instead of Innodb, replacing the ‘innodb_*’ settings with ‘skip-innodb’ can reduce memory usage even further.

Leave a Reply

Your email address will not be published. Required fields are marked *