Persistent memory-optimized instances, such as re6p instances, have high CPU-to-memory ratios and can run Redis applications with much lower costs per GiB of memory. This topic describes how to quickly deploy Redis applications 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
    Note To use ecs.re6p-redis.4xlarge, submit a ticket.
  • Images:
    • Alibaba Cloud Linux 2
    • CentOS 7.6 and later
    • Ubuntu 18.10 and later
    • SUSE Linux 12 SP4 and later

Deploy a Redis application on an instance that runs Alibaba Cloud Linux 2

Alibaba Cloud Linux 2 is tuned for Redis applications. Redis applications deployed on Alibaba Cloud Linux 2 outperform those deployed on community-supported Linux operating systems in overall performance 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 yum install command to deploy Redis 6.0.5 and Redis 3.2.12. You can also manually deploy Redis applications of other versions. For more information, see Deploy a Redis application on an instance that runs CentOS and Deploy a Redis application on an instance that runs Ubuntu.

In this example, the following configurations are used:
  • Instance type: ecs.re6p-redis.2xlarge
  • Image: Alibaba Cloud Linux 2.1903 LTS 64-bit
  1. 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.
  2. Log on to the instance.
    For more information, see Connection methods.
  3. Deploy Redis 6.0.5 or Redis 3.2.12.
    • Run the following command to deploy Redis 6.0.5:
      yum install -y alinux-release-experimentals && \
      yum install -y redis-6.0.5
    • Run the following command to deploy Redis 3.2.12:
      yum install -y alinux-release-experimentals && \
      yum install -y redis-3.2.12
  4. Configure network interface controller (NIC) multi-queue.
    NIC multi-queue helps improve the performance of Redis applications.
    wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/ecs_mq/ecs_mq_latest.tgz && \
    tar -xzf ecs_mq_latest.tgz && \
    cd ecs_mq && \
    bash install.sh aliyun 2 && \
    systemctl start ecs_mq
    Note Run a command in the format of bash install.sh <Operating system name> <Major version of the operating system>. For example, run the bash install.sh aliyun 2 command for an Alibaba Cloud Linux 2.1903 image. You must adjust the command parameters based on your image version.
  5. Start Redis and configure the default amounts of regular and persistent memory allocated to Redis.
    Sample commands:
    • Run the following command to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
      export MEMKIND_DAX_KMEM_NODES=1 && \
      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 customize a regular memory-to-persistent memory ratio and leave some regular memory available for other applications. For example, you can run the following command to set the regular memory-to-persistent memory ratio to 1:16 and the total amount of memory allocated to Redis to 34 GiB (including 2 GiB of regular memory and 32 GiB of persistent memory):
      export MEMKIND_DAX_KMEM_NODES=1 && \
      redis-server /etc/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 16 --maxmemory 34G

Deploy a Redis application on an instance that runs CentOS

In this example, the following configurations are used:
  • Instance type: ecs.re6p-redis.2xlarge
  • Image: CentOS 7.6
  • Redis: Redis 4.0.14
  • memkind: memkind 1.10.1-rc2
Note Resources required to perform some of the following steps need to be downloaded from GibHub at https://github.com/. Make sure that the required resources are downloaded before you proceed to the steps. If an attempt to download a resource from GitHub fails, repeat the corresponding command until the resource is downloaded.
  1. 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.
  2. Log on to the instance.
    For more information, see Connection methods.
  3. Prepare the compiling environment.
    export MEMKIND_DAX_KMEM_NODES=1 && \
    yum -y install numactl-devel.x86_64 && \
    yum -y groupinstall 'Development Tools'
  4. Prepare Redis 4.0.14 source code.
    wget https://github.com/redis-io/redis/archive/4.0.14.tar.gz && \
    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 applications to use persistent memory.
  5. Prepare memkind source code.
    memkind is a memory management tool used to allocate and manage persistent memory.
    1. Download memkind source code.
      wget https://github.com/memkind/memkind/archive/v1.10.1-rc2.tar.gz && \
      tar xzvf v1.10.1-rc2.tar.gz && \
      mv memkind-1.10.1-rc2/* ./deps/memkind
    2. Optional:Adjust Makefile.
      Note You can first run the ldd --version command to view the version of glibc. If the version of glibc is 2.17 or later, skip the following operations and compile Redis directly.
      cd ./deps/memkind && \
      wget https://github.com/memKeyDB/memKeyDB/wiki/files/0001-Use-secure_getenv-when-possible.patch && \
      git apply --ignore-whitespace 0001-Use-secure_getenv-when-possible.patch && \
      cd /root/redis-4.0.14
      Note If the patch cannot be downloaded, run the command that excludes cd ./deps/memkind && \
  6. Compile and install Redis.
    make clean && \
    make distclean && \
    make MALLOC=memkind -j 4 && \
    make install
  7. Configure NIC multi-queue.
    NIC multi-queue helps improve the performance of Redis applications.
    wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/ecs_mq/ecs_mq_latest.tgz && \
    tar -xzf ecs_mq_latest.tgz && \
    cd ecs_mq && \
    bash install.sh centos 7 && \
    systemctl start ecs_mq
    Note Run a command in the format of bash install.sh <Operating system name> <Major version of the operating system>. For example, run the bash install.sh centos 7 command for a CentOS 7.6 image. You must adjust the command parameters based on your image version.
  8. Start Redis and configure the default amounts of regular memory and persistent memory allocated to Redis.
    Sample commands:
    • Run the following command to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
      redis-server /root/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 customize a regular memory-to-persistent memory ratio and leave some regular memory available for other applications. For example, you can run the following command to set the regular memory-to-persistent memory ratio to 1:16 and the total amount of memory allocated to Redis to 34 GiB (including 2 GiB of regular memory and 32 GiB of persistent memory):
      redis-server /root/redis-4.0.14/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 16 --maxmemory 34G

Deploy a Redis application on an instance that runs Ubuntu

In this example, the following configurations are used:
  • Instance type: ecs.re6p-redis.2xlarge
  • Image: Ubuntu 20.04
  • Redis: Redis 6.2.5
  • memkind: memkind 1.10.1-rc2
Note Resources required to perform some of the following steps need to be downloaded from GibHub at https://github.com/. Make sure that the required resources are downloaded before you proceed to the steps. If an attempt to download a resource from GitHub fails, repeat the corresponding command until the resource is downloaded.
  1. 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.
  2. Log on to the instance.
    For more information, see Connection methods.
  3. Prepare the compiling environment.
    export MEMKIND_DAX_KMEM_NODES=1 && \
    apt update && \
    apt -y install git && \
    apt install -y libnuma-dev && \
    apt install -y numactl
  4. Prepare Redis 6.2.5 source code.
    wget https://download.redis.io/releases/redis-6.2.5.tar.gz && \
    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 applications to use persistent memory.
  5. Prepare memkind source code.
    memkind is a memory management tool used to allocate and manage persistent memory.
    1. Download memkind source code.
      wget https://github.com/memkind/memkind/archive/v1.10.1-rc2.tar.gz && \
      tar xzvf v1.10.1-rc2.tar.gz && \
      mv memkind-1.10.1-rc2/* ./deps/memkind/
    2. Adjust Makefile.
      Note You can first run the ldd --version command to view the version of glibc. If the version of glibc is 2.17 or later, skip the following operations and compile Redis directly.
      cd ./deps/memkind && \
      wget --no-check-certificate https://github.com/memKeyDB/memKeyDB/wiki/files/0001-Use-secure_getenv-when-possible.patch && \
      git apply --ignore-whitespace 0001-Use-secure_getenv-when-possible.patch && \
      cd /root/redis-6.2.5
      Note If the patch cannot be downloaded, run the command that excludes cd ./deps/memkind && \
  6. Compile and install Redis.
    make clean && \
    make distclean && \
    make MALLOC=memkind -j 4 && \
    make install
  7. Configure NIC multi-queue.
    NIC multi-queue helps improve the performance of Redis applications.
    wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/ecs_mq/ecs_mq_latest.tgz && \
    tar -xzf ecs_mq_latest.tgz && \
    cd ecs_mq && \
    bash install.sh ubuntu 20 && \
    systemctl start ecs_mq
    Note Run a command in the format of bash install.sh <Operating system name> <Major version of the operating system>. For example, run the bash install.sh ubuntu 20 command for a Ubuntu 20 image. You must adjust the command parameters based on your image version.
  8. Start Redis and configure the default amounts of regular memory and persistent memory allocated to Redis.
    Sample commands:
    • Run the following command to set the regular memory-to-persistent memory ratio to a recommended value of 1:4:
      redis-server /root/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 customize a regular memory-to-persistent memory ratio and leave some regular memory available for other applications. For example, you can run the following command to set the regular memory-to-persistent memory ratio to 1:16 and the total amount of memory allocated to Redis to 34 GiB (including 2 GiB of regular memory and 32 GiB of persistent memory):
      redis-server /root/redis-6.2.5/redis.conf --port 8369 --memory-alloc-policy ratio --dram-pmem-ratio 1 16 --maxmemory 34G

Download patches that enable Redis applications to use persistent memory

In the sample command, replace the download URL and the version number that corresponds to the file name. For example, run the following command to download a patch suitable for Redis 6.2.5:
wget https://github.com/redis/redis/compare/6.2.5...tieredmemdb:6.2.5-devel.diff -O redis_6.2.5_diff_tieredmemdb.patch