Install Redis applications on instances with persistent memory

更新时间:
复制 MD 格式

Instances with persistent memory, such as re7p, r7p, and re6p-redis, offer a high CPU-to-memory ratio. This lets you run Redis applications at a much lower cost per GiB of memory. This topic describes how to quickly deploy Redis applications on these instances for several operating systems.

Background information

The steps to quickly deploy Redis applications in this topic apply to specific instance types and image versions. The requirements are as follows:

  • Instance types:

    • re7p: ecs.re7p.large, ecs.re7p.xlarge, ecs.re7p.2xlarge, ecs.re7p.16large, and ecs.re7p.32xlarge

    • r7p: ecs.r7p.large, ecs.r7p.xlarge, ecs.r7p.2xlarge, ecs.r7p.16large, and ecs.r7p.32xlarge

    • re6p: 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 applications in Alibaba Cloud Linux 2

Alibaba Cloud Linux 2 is specifically optimized for Redis applications. It improves the overall performance of Redis applications by more than 20% compared to community operating systems.

Alibaba Cloud Linux 2 includes built-in yum sources for Redis 6.0.5 and Redis 3.2.12. You can run the sudo yum install command to deploy these versions. You can also manually deploy other versions of Redis. For more information, see Deploy Redis applications in CentOS and Deploy Redis applications in Ubuntu.

The resources in this section are configured as follows:

  • Instance type: ecs.re6p-redis.2xlarge

  • Image: Alibaba Cloud Linux 2.1903 LTS 64-bit

  1. Purchase a persistent memory instance.

    For more information, see Create a custom instance. Note the following configurations:

    • Instance: Under the x86-Compute architecture, click Memory-optimized Type and select the ecs.re6p-redis.2xlarge instance type.

    • Images: 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 as needed.

    • To deploy Redis 6.0.5:

      sudo yum install -y alinux-release-experimentals && \
      sudo yum install -y redis-6.0.5
    • To deploy Redis 3.2.12:

      sudo yum install -y alinux-release-experimentals && \
      sudo yum install -y redis-3.2.12
  4. Start the Redis application and configure the DRAM and persistent memory capacity.

    The following are example commands:

    • The recommended ratio of DRAM to persistent memory is 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 customize the ratio of DRAM to persistent memory to reserve some DRAM for other applications. For example, you can set the ratio to 1:16 and allocate 34 GiB of memory, which includes 2 GiB of DRAM 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 applications in CentOS

The resources and software in this section are configured as follows:

  • Instance type: ecs.re6p-redis.2xlarge

  • Image: CentOS 7.6

  • Redis: Redis 4.0.14

  • memkind: memkind 1.10.1-rc2

Note

Ensure that the resources are downloaded from https://github.com/ before you proceed. If a download fails, rerun the command until the download is successful.

  1. Purchase a persistent memory instance.

    For more information, see Create a custom instance. Note the following configurations:

    • Instance: For the x86-Compute architecture, click Memory-optimized Type and select the ecs.re6p-redis.2xlarge instance type.

    • Images: Select CentOS 7.6 (64-bit).

  2. Log on to the instance.

    For more information, see Connection methods.

  3. You can prepare the compilation environment.

    export MEMKIND_DAX_KMEM_NODES=1 && \
    sudo yum -y install numactl-devel.x86_64 && \
    sudo yum -y groupinstall 'Development Tools'
  4. Prepare the 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

    This patch enables persistent memory. Different Redis versions require different patches. For more information, see Download patches to enable persistent memory.

  5. Prepare the memkind source code.

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

    1. Download the 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 ldd --version to check the glibc version. If the glibc version is earlier than 2.17, upgrade the glibc version. For more information, see View and upgrade the glibc version. If the glibc version is 2.17 or later, you can skip the following steps and directly 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 fails to download, do not include cd ./deps/memkind && \ when you run the command again.

  6. Compile and install Redis.

    make clean && \
    make distclean && \
    make MALLOC=memkind -j 4 && \
    sudo make install
  7. Start the Redis application and configure the DRAM and persistent memory capacity.

    The following are example commands:

    Note

    Replace /home/user with the actual user folder.

    • The recommended ratio of DRAM to persistent memory is 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 customize the ratio of DRAM to persistent memory to reserve some DRAM for other applications. For example, you can set the ratio to 1:16 and allocate 34 GiB of memory, which includes 2 GiB of DRAM 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 applications in Ubuntu

The resources and software in this section are configured as follows:

  • Instance type: ecs.re6p-redis.2xlarge

  • Image: Ubuntu 20.04

  • Redis: Redis 6.2.5

  • memkind: memkind 1.10.1-rc2

Note

Before you proceed, make sure that the resources are downloaded from https://github.com/. If a download fails, run the command again until the download is successful.

  1. Purchase a persistent memory-optimized instance.

    For more information, see Create a custom instance. Note the following configurations:

    • Instance: In the x86-Compute architecture section, click Memory-optimized Type and select the ecs.re6p-redis.2xlarge instance type.

    • Images: Select Ubuntu 20.04 64-bit.

  2. Log on to the instance.

    For more information, see Connection methods.

  3. Prepare the compilation 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 the 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. Different Redis versions require different patches. For more information, see Download patches to enable persistent memory.

  5. Prepare the memkind source code.

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

    1. Download the 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 ldd --version to check the glibc version. If the glibc version is earlier than 2.17, upgrade the glibc version. For more information, see View and upgrade the glibc version. If the glibc version is 2.17 or later, you can skip the following steps and directly 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 fails to download, do not include cd ./deps/memkind && \ when you run the command again.

  6. Compile and install Redis.

    make clean && \
    make distclean && \
    make MALLOC=memkind -j 4 && \
    sudo make install
  7. Start the Redis application and configure the DRAM and persistent memory capacity.

    The following are example commands:

    Note

    Replace /home/user with the path to the actual user folder.

    • The recommended ratio of DRAM to persistent memory is 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 customize the ratio of DRAM to persistent memory to reserve some DRAM for other applications. For example, you can set the ratio to 1:16 and allocate 34 GiB of memory, consisting of 2 GiB of DRAM 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 to enable persistent memory

Replace the download URL and version number in the file name in the example command. For example, the command to download the patch for Redis 6.2.5 is as follows:

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 download URLs for the supported patches are as follows: