All Products
Search
Document Center

:Deploy a Redis instance with an NVM volume mounted as direct memory

Last Updated:Nov 20, 2024

In Container Service for Kubernetes (ACK), direct access to persistent memory (PMEM) devices enables high throughput and low latency. This topic describes how to use dynamic random-access memory (DRAM) and PMEM to deploy in-memory Redis instances that require large memory capacity.

Background information

If you want to deploy in-memory Redis instances that require large memory capacity, you can mount NVM (non-volatile memory) volumes as direct memory. This solution provides the following benefits:

  • NVM volumes are accessed in a declarative manner. This simplifies the use of NVM resources.

  • With the same memory capacity, costs can be reduced by 30% to 50%.

  • Modifications to applications are minimized.

Redis uses NVM devices as direct memory and calls the MMAP function to map the consecutive address space of PMEM. In this case, specific Redis versions are required. The following examples show how to query the images of Redis instances.

Use DRAM to deploy an in-memory Redis instance

DRAM provides high-speed access performance but loses data when power is off. DRAM does not apply to large-scale scenarios due to its high costs.

  1. Perform the following steps to deploy a Redis instance:

    1. Use the following sample template to create a redis-normal.yaml file:

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: redis-normal
        labels:
          app: redis-normal
      spec:
        selector:
          matchLabels:
            app: redis-normal
        template:
          metadata:
            labels:
              app: redis-normal
          spec:
            containers:
            - name: redis
              image: registry.cn-hangzhou.aliyuncs.com/plugins/redis:v1-normal
              imagePullPolicy: Always
              resources:
                requests:
                  memory: 30Gi
                limits:
                  memory: 30Gi
    2. Run the following command to deploy the Redis instance:

      kubectl apply -f redis-normal.yaml
  2. Run the following command to query the pod that runs the Redis instance:

    kubectl get pod | grep redis-normal

    Expected output:

    redis-normal-***         1/1     Running   0          4d8h
  3. Run the following command to test the write performance of the Redis instance:

    LD_PRELOAD=/usr/local/lib/libmemkind.so redis-benchmark -d 102400 -t set -n 1000000 -r 1000000

    Expected output:

    1000000 requests completed in 13.03 seconds
    76751.86 requests per second

    The preceding output shows that the in-memory Redis instance that is deployed with DRAM can process approximately 76,751 requests per second.

Use PMEM to deploy an in-memory Redis instance

PMEM provides non-volatile storage and is similar to DRAM in terms of access method and speed.

  1. Run the following command to deploy an in-memory Redis instance:

    kubectl apply -f redis-normal.yaml

    The following template provides an example of the redis-normal.yaml file:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pmem-pvc-direct
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 60Gi
      storageClassName: csi-pmem-direct
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: redis-pmem-direct
      labels:
        app: redis-pmem-direct
    spec:
      selector:
        matchLabels:
          app: redis-pmem-direct
      template:
        metadata:
          labels:
            app: redis-pmem-direct
        spec:
          containers:
          - name: nginx
            image: registry.cn-hangzhou.aliyuncs.com/plugins/redis:v1-pmem
            imagePullPolicy: Always
            volumeMounts:
              - name: pmem-pvc
                mountPath: "/mnt/pmem"
          volumes:
            - name: pmem-pvc
              persistentVolumeClaim:
                claimName: pmem-pvc-direct
  2. Run the following command to query the pod that runs the Redis instance:

    kubectl get pod | grep redis-pmem-direct

    Expected output:

    redis-pmem-direct-5b469546db-5tk2j   1/1     Running   0          4d9h
  3. Run the following command to test the write performance of the Redis instance:

    LD_PRELOAD=/usr/local/lib/libmemkind.so redis-benchmark -d 10240 -t set -n 1000000 -r 1000000

    Expected output:

    1000000 requests completed in 19.89 seconds
    50266.41 requests per second

    The preceding output shows that the in-memory Redis instance that is deployed with PMEM can process about 50,266 requests per second.

    Compared with the in-memory Redis instance deployed with DRAM, the in-memory Redis instance deployed with PMEM reduces the write performance by 34% but offers the same read performance and saves cost by 50%. Elastic Compute Service (ECS) instance types with NVM devices, such as ecs.ebmre6p.26xlarge, offer 1.5 TB of MEM memory, which is five times the capacity of common in-memory databases.