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
- 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 ""
- 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
- Max Memory Policy: Decide what Redis should do when
maxmemory-policy allkeys-lru # Least Recently Used Key eviction
- Disable TCP Timestamps: Disable TCP timestamps to improve speed.
- Hash Max Ziplist Entries: For small hashes, you can set a high max ziplist entries.
- Hash Max Ziplist Value: For small hash values, you can set a high max ziplist value.
- Set CPU Cores: Bind Redis to fewer cores if you’re running other heavy applications.
# bind 127.0.0.1 ::1
- Log Level: If you don’t need detailed logs, you can set the log level to warning.
- Enable Transparent Huge Pages (THP): Disable Linux Transparent Huge Pages, as it can affect Redis performance.
echo never > /sys/kernel/mm/transparent_hugepage/enabled
- Sysctl Optimization: Adjust system-level TCP configurations.
bash sysctl -w net.core.somaxconn=65535 sysctl -w vm.overcommit_memory=1
Steps to Apply Changes:
- Open the Redis configuration file.
- Make the changes as per your requirements.
- Save and exit the editor.
- 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.