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.
Perform the following steps to deploy a Redis instance:
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: 30GiRun the following command to deploy the Redis instance:
kubectl apply -f redis-normal.yaml
Run the following command to query the pod that runs the Redis instance:
kubectl get pod | grep redis-normalExpected output:
redis-normal-*** 1/1 Running 0 4d8hRun 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 1000000Expected output:
1000000 requests completed in 13.03 seconds 76751.86 requests per secondThe 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.
Run the following command to deploy an in-memory Redis instance:
kubectl apply -f redis-normal.yamlThe 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-directRun the following command to query the pod that runs the Redis instance:
kubectl get pod | grep redis-pmem-directExpected output:
redis-pmem-direct-5b469546db-5tk2j 1/1 Running 0 4d9hRun 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 1000000Expected output:
1000000 requests completed in 19.89 seconds 50266.41 requests per secondThe 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.