How to Configure Memcached Memory Allocation on Linux (Xeon Server with 32GB RAM Case Study)


1 views

For Red Hat/CentOS systems, the primary configuration file for Memcached is located at:

/etc/sysconfig/memcached

This is where you'll define your memory allocation settings. The file uses simple key-value pairs for configuration.

Open the configuration file with your preferred text editor (vim/nano):

sudo vim /etc/sysconfig/memcached

Look for or add the CACHESIZE parameter. For 1GB allocation:

CACHESIZE="1024"

For optimal performance on your Xeon server with 32GB RAM, consider these parameters:

OPTIONS="-l 127.0.0.1 -t 8 -m 1024 -c 1024"

Where:

  • -t 8: Sets threads (matches your Xeon 7550's 8 cores)
  • -c 1024: Increases max simultaneous connections

After saving changes, restart the service and verify:

sudo systemctl restart memcached
sudo systemctl status memcached
memstat --servers=localhost

If you prefer running memcached directly:

memcached -d -m 1024 -u memcached -l 127.0.0.1 -p 11211

Use the following command to check real-time memory allocation:

echo "stats" | nc localhost 11211 | grep bytes

This will show you the actual memory being used by your Memcached instance.


On RedHat-based systems, the main configuration file for Memcached is typically found at:

/etc/sysconfig/memcached

For some installations, you might also check:

/etc/memcached.conf

Open the file with your preferred editor (as root):

sudo vi /etc/sysconfig/memcached

Look for the CACHESIZE parameter. If it doesn't exist, add it:

CACHESIZE="1024"

This sets the memory allocation to 1GB (1024MB).

For systems using /etc/memcached.conf, the format differs slightly:

# Memory allocation in megabytes
-m 1024

After saving the file, restart Memcached:

sudo service memcached restart

Check the allocated memory:

echo "stats" | nc localhost 11211 | grep "limit_maxbytes"

You should see output similar to:

STAT limit_maxbytes 1073741824

For optimal performance on your Xeon 7550 with 32GB RAM:

# Connection settings
MAXCONN="1024"
# Binding IP (adjust as needed)
OPTIONS="-l 127.0.0.1"
# Memory allocation
CACHESIZE="1024"

If Memcached fails to start after changes:

# Check logs
tail -f /var/log/memcached.log
# Verify syntax
sudo service memcached configtest

Remember that the allocated memory should leave sufficient RAM for other services.