Persistent memory-optimized instances, such as re6p instances, have high CPU-to-memory ratios and can run Redis with much lower costs per GiB of memory. This topic describes how to quickly deploy Redis on persistent memory-optimized instances. In the examples, some operating systems are used.
Background information
The procedures described in this topic are applicable only to the following instance types and image versions:- Instance types: ecs.re6p-redis.large, ecs.re6p-redis.xlarge, ecs.re6p-redis.2xlarge, ecs.re6p-redis.4xlarge, and ecs.re6p-redis.13xlarge
- Images:
- Alibaba Cloud Linux 2
- CentOS 7.6 or later
- Ubuntu 18.04 or Ubuntu 20.04
Deploy Redis on an instance that runs Alibaba Cloud Linux 2
Alibaba Cloud Linux 2 is specially tuned for Redis applications. Redis applications that are deployed on Alibaba Cloud Linux 2 outperform Redis applications that deployed on community-supported operating systems by more than 20%.
The YUM repositories of Redis 6.0.5 and Redis 3.2.12 are built-in to Alibaba Cloud Linux 2. You can run the sudo yum install command to deploy Redis 6.0.5 and Redis 3.2.12. You can also manually deploy other Redis versions. For more information, see Deploy Redis on an instance that runs CentOS and Deploy Redis on an instance that runs Ubuntu.
- Instance type: ecs.re6p-redis.2xlarge
- Image: Alibaba Cloud Linux 2.1903 LTS 64-bit
- Purchase a persistent memory-optimized instance. For more information, see Create an instance by using the wizard. Take note of the following configurations:
- Instance Type: Set Architecture to x86-Architecture, set Category to Memory Optimized, and then select the ecs.re6p-redis.2xlarge instance type.
- Image: Select Alibaba Cloud Linux 2.1903 LTS 64-bit.
- Log on to the instance. For more information, see Connection methods.
- Deploy Redis 6.0.5 or Redis 3.2.12 based on your business requirements.
- Run the following commands to deploy Redis 6.0.5:
sudo yum install -y alinux-release-experimentals && \ sudo yum install -y redis-6.0.5
- Run the following commands to deploy Redis 3.2.12:
sudo yum install -y alinux-release-experimentals && \ sudo yum install -y redis-3.2.12
- Run the following commands to deploy Redis 6.0.5:
- Start Redis and configure the default amounts of regular memory and persistent memory that are allocated to Redis. Sample commands:
- Run the following commands to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
export MEMKIND_DAX_KMEM_NODES=1 && \ sudo redis-server /etc/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 4 --hashtable-on-dram yes --daemonize yes --logfile /tmp/redis_8369.log --protected-mode no --bind 0.0.0.0
- You can also specify a different regular memory-to-persistent memory ratio and leave some regular memory to other applications. For example, you can run the following commands to set the regular memory-to-persistent memory ratio to 1:16 and allocate 34 GiB of memory in total to Redis, including 2 GiB of regular memory and 32 GiB of persistent memory:
export MEMKIND_DAX_KMEM_NODES=1 && \ sudo redis-server /etc/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 16 --maxmemory 34G
- Run the following commands to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
Deploy Redis on an instance that runs CentOS
- Instance type: ecs.re6p-redis.2xlarge
- Image: CentOS 7.6
- Redis: Redis 4.0.14
- memkind: memkind 1.10.1-rc2
- Purchase a persistent memory-optimized instance. For more information, see Create an instance by using the wizard. Take note of the following configurations:
- Instance Type: Set Architecture to x86-Architecture, set Category to Memory Optimized, and then select the ecs.re6p-redis.2xlarge instance type.
- Image: Select CentOS 7.6 64-bit.
- Log on to the instance. For more information, see Connection methods.
- Prepare the compiling environment.
export MEMKIND_DAX_KMEM_NODES=1 && \ sudo yum -y install numactl-devel.x86_64 && \ sudo yum -y groupinstall 'Development Tools'
- Prepare Redis 4.0.14 source code.
sudo wget https://github.com/redis-io/redis/archive/4.0.14.tar.gz && \ sudo wget https://github.com/redis/redis/compare/4.0.14...tieredmemdb:4.0.14-devel.diff -O redis_4.0.14_diff_tieredmemdb.patch && \ tar xzvf 4.0.14.tar.gz && \ cd redis-4.0.14 && \ git apply --ignore-whitespace ../redis_4.0.14_diff_tieredmemdb.patch
Note The patch is used to enable persistent memory and varies per Redis version. For more information, see Download patches that enable Redis to use persistent memory. - Prepare memkind source code. memkind is a memory management tool that is used to allocate and manage persistent memory.
- Compile and install Redis.
make clean && \ make distclean && \ make MALLOC=memkind -j 4 && \ sudo make install
- Start Redis and configure the default amounts of regular memory and persistent memory that are allocated to Redis. Sample commands:Note Replace /home/user with the actual user directory.
- Run the following commands to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
redis-server /home/user/redis-4.0.14/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 4 --hashtable-on-dram yes --daemonize yes --logfile /tmp/redis_8369.log --protected-mode no --bind 0.0.0.0
- You can also specify a different regular memory-to-persistent memory ratio and leave some regular memory to other applications. For example, you can run the following commands to set the regular memory-to-persistent memory ratio to 1:16 and allocate 34 GiB of memory in total to Redis, including 2 GiB of regular memory and 32 GiB of persistent memory:
redis-server /home/user/redis-4.0.14/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 16 --maxmemory 34G
- Run the following commands to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
Deploy Redis on an instance that runs Ubuntu
- Instance type: ecs.re6p-redis.2xlarge
- Image: Ubuntu 20.04
- Redis: Redis 6.2.5
- memkind: memkind 1.10.1-rc2
- Purchase a persistent memory-optimized instance. For more information, see Create an instance by using the wizard. Take note of the following configurations:
- Instance Type: Set Architecture to x86-Architecture, set Category to Memory Optimized, and then select the ecs.re6p-redis.2xlarge instance type.
- Image: Select Ubuntu 20.04 64-bit.
- Log on to the instance. For more information, see Connection methods.
- Prepare the compiling environment.
export MEMKIND_DAX_KMEM_NODES=1 && \ sudo apt update && \ sudo apt -y install git && \ sudo apt install -y libnuma-dev && \ sudo apt install -y numactl
- Prepare Redis 6.2.5 source code.
sudo wget https://download.redis.io/releases/redis-6.2.5.tar.gz && \ sudo wget https://github.com/redis/redis/compare/6.2.5...tieredmemdb:6.2.5-devel.diff -O redis_6.2.5_diff_tieredmemdb.patch && \ tar xzf redis-6.2.5.tar.gz && \ cd redis-6.2.5 && \ git apply --ignore-whitespace ../redis_6.2.5_diff_tieredmemdb.patch
Note The patch is used to enable persistent memory and varies per Redis version. For more information, see Download patches that enable Redis to use persistent memory. - Prepare memkind source code. memkind is a memory management tool that is used to allocate and manage persistent memory.
- Compile and install Redis.
make clean && \ make distclean && \ make MALLOC=memkind -j 4 && \ sudo make install
- Start Redis and configure the default amounts of regular memory and persistent memory that are allocated to Redis. Sample commands:Note Replace /home/user with the actual user directory.
- Run the following commands to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
redis-server /home/user/redis-6.2.5/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 4 --hashtable-on-dram yes --daemonize yes --logfile /tmp/redis_8369.log --protected-mode no --bind 0.0.0.0
- You can also specify a different regular memory-to-persistent memory ratio and leave some regular memory to other applications. For example, you can run the following commands to set the regular memory-to-persistent memory ratio to 1:16 and allocate 34 GiB of memory in total to Redis, including 2 GiB of regular memory and 32 GiB of persistent memory:
redis-server /home/user/redis-6.2.5/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 16 --maxmemory 34G
- Run the following commands to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
Download patches that enable Redis to use persistent memory
sudo wget https://github.com/redis/redis/compare/6.2.5...tieredmemdb:6.2.5-devel.diff -O redis_6.2.5_diff_tieredmemdb.patch
- Redis 6.2
https://github.com/redis/redis/compare/6.2.5...tieredmemdb:6.2.5-devel.diff
- Redis 6.0
- https://github.com/redis/redis/compare/6.0.9...tieredmemdb:6.0.9-devel.diff
- https://github.com/redis/redis/compare/6.0.5...tieredmemdb:6.0.5-devel.diff
- https://github.com/redis/redis/compare/6.0.3...tieredmemdb:6.0.3-devel.diff
- https://github.com/redis/redis/compare/6.0.0...tieredmemdb:6.0.0-devel.diff
- Redis 5.0
- Redis 4.0
- https://github.com/redis/redis/compare/4.0.14...tieredmemdb:4.0.14-devel.diff
- https://github.com/redis/redis/compare/4.0.9...tieredmemdb:4.0.9-devel.diff
- https://github.com/redis/redis/compare/4.0.2...tieredmemdb:4.0.2-devel.diff
- https://github.com/redis/redis/compare/4.0.0...tieredmemdb:4.0.0-devel.diff
- Redis 3.0
https://github.com/redis/redis/compare/3.2.12...tieredmemdb:3.2.diff