All Products
Search
Document Center

Elastic Compute Service:install Redis on persistent memory-optimized instances

Last Updated:Mar 22, 2024

Persistent memory-optimized Elastic Compute Service (ECS) instances such as re6p instances, have high CPU-to-memory ratios and can run Redis with reduced costs per GiB of memory. This topic describes how to quickly deploy Redis on persistent memory-optimized instances. In the examples, specific operating systems are used.

Background information

The procedure described in this topic is 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

  • Image versions

    • Alibaba Cloud Linux 2

    • CentOS 7.6 and later

    • Ubuntu 18.04 and 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 are 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 deploy Redis applications of other versions. For more information, see the Deploy Redis on an instance that runs CentOS and Deploy Redis on an instance that runs Ubuntu sections in this topic.

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 on the Custom Launch tab. Take note of the following configurations:

    • Instance: Select Memory-optimized from the x86 drop-down list in the Architecture section 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 method overview.

  3. 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
  4. 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 specify a different regular memory-to-persistent memory ratio and allocate specific 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 a total of 34 GiB of memory 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

Deploy Redis 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

Some of the following steps require specific resources from GitHub. Make sure that the resources are downloaded from https://github.com/ before you perform the steps. If a resource cannot be downloaded from GitHub, repeat the relevant command until the resource is downloaded.

  1. Purchase a persistent memory-optimized instance.

    For more information, see Create an instance on the Custom Launch tab. Take note of the following configurations:

    • Instance: Select Memory-optimized from the x86 drop-down list in the Architecture section 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 method overview.

  3. Prepare the compiling environment.

    export MEMKIND_DAX_KMEM_NODES=1 && \
    sudo yum -y install numactl-devel.x86_64 && \
    sudo yum -y groupinstall 'Development Tools'
  4. 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 based on the Redis version. For more information, see the Download patches that enable Redis to use persistent memory section in this topic.

  5. Prepare memkind source code.

    memkind is a memory management tool that is used to allocate and manage persistent memory.

    1. Download memkind source code.

      sudo 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 the Makefile.

      Note

      You can 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.

      cd ./deps/memkind && \
      sudo 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 ../../
      Note

      If the patch cannot be downloaded, run the commands that exclude the cd ./deps/memkind && \ command.

  6. Compile and install Redis.

    make clean && \
    make distclean && \
    make MALLOC=memkind -j 4 && \
    sudo make install
  7. 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 specify a different regular memory-to-persistent memory ratio and allocate specific 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 a total of 34 GiB of memory 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

Deploy Redis 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

Some of the following steps require specific resources from GitHub. Make sure that the resources are downloaded from https://github.com/ before you perform the steps. If a resource cannot be downloaded from GitHub, repeat the relevant command until the resource is downloaded.

  1. Purchase a persistent memory-optimized instance.

    For more information, see Create an instance on the Custom Launch tab. Take note of the following configurations:

    • Instance: Select Memory-optimized from the x86 drop-down list in the Architecture section 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 method overview.

  3. 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
  4. 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 based on the Redis version. For more information, see the Download patches that enable Redis to use persistent memory section in this topic.

  5. Prepare memkind source code.

    memkind is a memory management tool that is used to allocate and manage persistent memory.

    1. Download memkind source code.

      sudo 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 the Makefile.

      Note

      You can 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.

      cd ./deps/memkind && \
      sudo 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 ../../
      Note

      If the patch cannot be downloaded, run the commands that exclude the cd ./deps/memkind && \ command.

  6. Compile and install Redis.

    make clean && \
    make distclean && \
    make MALLOC=memkind -j 4 && \
    sudo make install
  7. 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 specify a different regular memory-to-persistent memory ratio and allocate specific 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 a total of 34 GiB of memory 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

Download patches that enable Redis 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:

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

The following section provides the download URLs for supported patches: