Summary:
We have a use case to store values size of 100KB to 650KB in etcd, however the total number of keys are not more than 2000.
But we observe etcd memory consumption keeps on increasing and eventually leading to OOM error, sometime it takes just few hours and sometime 2 to 3 days.
Details:
- ETCD Version:
bash-4.4$ etcd -version
etcd Version: 3.3.11
Git SHA: 2cf9e51d2
Go Version: go1.10.7
Go OS/Arch: linux/amd64
bash-4.4$
- ETCD Members: 3
- ETCD Quota Backend Size: 256 MB
- Container Max Memory: 1 GB (We also tried to make it 2Gi but facing same problem)
- We tried to set/reduce below parameters one by one with the hope of improvement, but it didn't seem to be helping:
ETCD_AUTO_COMPACTION_RETENTION=1
ETCD_SNAPSHOT_COUNT=100
GOGC=20
GODEBUG="madvdontneed=1
Steps to Reproduce:
To quickly reproduce the issue, store huge value (1MB) size KV in etcd same key frequently. (This is nearly similar to our use case well)
- Execute below command to store 1MB size values in same key repeatedly for 250 times:
for i in {1..250}; do dd if=/dev/urandom bs=1024 count=1024 | ETCDCTL_API=3 etcdctl put key || break; done
- Execute below commands to compact and defragment the etcd backend database:
etcdctl compact `(etcdctl endpoint status --write-out="json" | egrep -o '"revision":[0-9]*' | egrep -o '[0-9]*')`
etcdctl defrag
etcdctl alarm disarm
- Repeat Step 1& 2 for 3 to 4 times and you will see each time etcd memory consumption is increasing, and eventually it leads to OOM with more such repetitions.
- Collect the heap profile from https://:2379/debug/pprof/heap, it will show increased heap usage for raft Entries, which keep on increasing with put entries and never gets released, below is the snippet of it:
File: etcd
Type: inuse_space
Time: Dec 14, 2020 at 2:45pm (IST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top10
Showing nodes accounting for 790.67MB, 98.83% of 800.03MB total
Dropped 49 nodes (cum <= 4MB)
Showing top 10 nodes out of 33
flat flat% sum% cum cum%
497.65MB 62.20% 62.20% 497.65MB 62.20% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/raft/raftpb.(*Entry).Unmarshal
282.54MB 35.32% 97.52% 282.54MB 35.32% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb.(*InternalRaftRequest).Marshal
5.24MB 0.65% 98.17% 5.24MB 0.65% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/rafthttp.(*streamWriter).closeUnlocked
5.24MB 0.65% 98.83% 5.24MB 0.65% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/rafthttp.startPeer
0 0% 98.83% 282.54MB 35.32% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/etcdserver.(*EtcdServer).Put
0 0% 98.83% 5.24MB 0.65% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/etcdserver.(*EtcdServer).apply
0 0% 98.83% 5.24MB 0.65% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/etcdserver.(*EtcdServer).applyAll
0 0% 98.83% 5.24MB 0.65% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/etcdserver.(*EtcdServer).applyConfChange
0 0% 98.83% 5.24MB 0.65% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/etcdserver.(*EtcdServer).applyEntries
0 0% 98.83% 282.54MB 35.32% github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/etcdserver.(*EtcdServer).processInternalRaftRequestOnce
(pprof)
Please let us know if any more details needed to help you to reproduce the issue.
Summary:
We have a use case to store values size of 100KB to 650KB in etcd, however the total number of keys are not more than 2000.
But we observe etcd memory consumption keeps on increasing and eventually leading to OOM error, sometime it takes just few hours and sometime 2 to 3 days.
Details:
Steps to Reproduce:
To quickly reproduce the issue, store huge value (1MB) size KV in etcd same key frequently. (This is nearly similar to our use case well)
Please let us know if any more details needed to help you to reproduce the issue.