Optimize Redis on CentOS 7

Optimizing Redis configuration involves various parameters that you can tweak based on your specific use case and workload. Below are some key configurations that you might consider tuning in your Redis setup on CentOS 7. The configuration file for Redis is usually located at /etc/redis.conf.

  1. Persistence Options: If you can afford to lose some data when the system crashes, you can disable persistence for a performance boost. appendonly no save ""
  2. Max Memory: Define a memory limit that Redis should not exceed. This is crucial for avoiding system swaps. maxmemory 2gb # Adjust based on your system's available RAM
  3. Max Memory Policy: Decide what Redis should do when maxmemory is reached. maxmemory-policy allkeys-lru # Least Recently Used Key eviction
  4. Disable TCP Timestamps: Disable TCP timestamps to improve speed. tcp-keepalive 300
  5. Hash Max Ziplist Entries: For small hashes, you can set a high max ziplist entries. hash-max-ziplist-entries 512
  6. Hash Max Ziplist Value: For small hash values, you can set a high max ziplist value. hash-max-ziplist-value 64
  7. Set CPU Cores: Bind Redis to fewer cores if you’re running other heavy applications. # bind 127.0.0.1 ::1
  8. Log Level: If you don’t need detailed logs, you can set the log level to warning. loglevel warning
  9. Enable Transparent Huge Pages (THP): Disable Linux Transparent Huge Pages, as it can affect Redis performance. echo never > /sys/kernel/mm/transparent_hugepage/enabled
  10. Sysctl Optimization: Adjust system-level TCP configurations.
    bash sysctl -w net.core.somaxconn=65535 sysctl -w vm.overcommit_memory=1

Steps to Apply Changes:

  1. Open the Redis configuration file. vi /etc/redis.conf
  2. Make the changes as per your requirements.
  3. Save and exit the editor.
  4. Restart Redis to apply the changes.
    bash systemctl restart redis

Remember, the above options are general guidelines. The optimal settings for your Redis instance might vary depending on your specific use case and workload. Always test changes in a staging environment before applying them to production.

Tags:

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.