dragonflydb / dragonfly

A modern replacement for Redis and Memcached
https://www.dragonflydb.io/
Other
25.21k stars 908 forks source link

Do we need to manually set the value of maxMemory when running on Kubernetes #418

Closed chenlein closed 1 year ago

chenlein commented 1 year ago

Describe the bug

[root@m-1 ~]# kubectl logs -f -n dmcca-system dragonfly-0  
I20221021 06:17:08.168525     1 init.cc:56] dragonfly running in opt mode.
I20221021 06:17:08.168985     1 dfly_main.cc:271] Starting dragonfly df-v0.10.0-10c3d9f66607c856d04d918059ddb9397aee4725
I20221021 06:17:08.169003     1 dfly_main.cc:303] Max memory limit is: 3.20GiB
W20221021 06:17:08.169049     1 dfly_main.cc:206] Kernel is older than 5.10, switching to epoll engine.
I20221021 06:17:08.173138     1 proactor_pool.cc:66] Running 16 io threads
E20221021 06:17:08.173208     1 dfly_main.cc:127] Max memory is less than 256MB per thread. Exiting...

To Reproduce

cat << EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: dragonfly-0
spec:
  containers:
  - command:
    - /bin/bash
    - -c
    - ulimit -l unlimited && dragonfly --alsologtostderr --maxmemory $(($(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) * 80 / 100))
    image: docker.dragonflydb.io/dragonflydb/dragonfly:v0.10.0
    imagePullPolicy: IfNotPresent
    livenessProbe:
      failureThreshold: 3
      httpGet:
        path: /
        port: 6379
        scheme: HTTP
      periodSeconds: 10
      successThreshold: 1
      timeoutSeconds: 1
    name: dragonfly
    readinessProbe:
      failureThreshold: 3
      httpGet:
        path: /
        port: 6379
        scheme: HTTP
      periodSeconds: 10
      successThreshold: 1
      timeoutSeconds: 1
    resources:
      limits:
        cpu: "2"
        memory: 4Gi
      requests:
        cpu: "0"
        memory: "0"
    securityContext:
      privileged: true
EOF

Expected behavior Automatically calculate Max Memory value for containers

Environment (please complete the following information):

 - OS: [CentOS Linux release 7.6.1810 (Core) ]
 - Kernel: Linux m-1 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
 - Containerized?: [Kubernetes + ContainerD]
 - Dragonfly Version: [v0.10.0]
romange commented 1 year ago

you should pass --proactor_threads=2 to limit the number of cpus if I read your yaml correctly. The problem is that you limit dragonfly to less than 4GB but your VM has 16 cpus and dragonfly requires at least 256MB per thread. By limiting number of threads to your actual limits you solve the problem.

chenlein commented 1 year ago

@romange Is it possible to automatically calculate threads and memory based on the pod's resources?

romange commented 1 year ago

Dragonfly binary does not calculate automatically container resources. My intuition says this approach does not sound right to me. All databases I know use flags/configuration files to set up these things. Do you know any other project (binary) that does it?

chenlein commented 1 year ago

maybe you are right, thanks for your help!