Repository navigation
After etcd cluster upgraded from v3.4.34 -> v3.5.27, TotalDBSize has been increased and TotalDBSizeInUse remains stable.
#22012
Replies: 4 comments 2 replies
|
Q1 — Is this expected after upgrading to v3.5.x? Yes, this is expected and well-understood behavior. The v3.5 default change from With
With
Q2 — Has the The benchmarks that motivated the For clusters in the 8–10 GiB range you can safely switch back to This restores v3.4 behavior: the freelist is persisted, free pages are reused aggressively, and Q3 — Are there other changes that could contribute? Two v3.5 changes are worth knowing about but are secondary to the freelist change:
Defrag frequency concern You noted that frequent defragmentation is undesirable due to leader election risk. With |
|
The default backend freelist type resolves to bolt.FreelistMapType: any --backend-bbolt-freelist-type value other than the literal string "array" (including the empty default) is parsed as map. (server/embed/config.go:1373, server/embed/config.go:115, server/embed/config.go:617) On Linux, etcd always opens bbolt with NoFreelistSync: true, so the freelist is NOT persisted to disk under either freelist type; the array/map setting only selects the in-memory allocator structure passed via bopts.FreelistType. (server/storage/backend/config_linux.go:29, server/storage/backend/config_linux.go:31, server/storage/backend/backend.go:196) etcd_mvcc_db_total_size_in_bytes reports physical file size (tx.Size()) and etcd_mvcc_db_total_size_in_use_in_bytes reports size minus FreePageN*PageSize, both refreshed on every transaction begin; therefore a growing gap between the two metrics is exactly an accumulation of free pages inside the db file. (server/storage/mvcc/metrics.go:171, server/storage/mvcc/metrics.go:188, server/storage/mvcc/kvstore.go:527) Compaction deletes old revisions (reducing sizeInUse) but never shrinks the file; only defragmentation rewrites the database into a tmp file and swaps it, which is the sole code path that resets b.size downward. (server/storage/mvcc/kvstore_compaction.go:57, server/storage/mvcc/kvstore_compaction.go:70, server/storage/backend/backend.go:556) etcd supports automatic defrag at bootstrap when (size - sizeInUse) exceeds BootstrapDefragThresholdMegabytes (maybeDefragBackend), an existing mitigation that avoids live-member unavailability by defragging during restarts. (server/etcdserver/bootstrap.go:307, server/etcdserver/bootstrap.go:310, server/etcdserver/bootstrap.go:312) A possible explanation — not yet verified: The behavior is 'expected' in the sense that it is benign free-page accumulation reclaimable by defrag, not a leak of live data — sizeInUse stability shows the logical dataset is unchanged. This could be checked by: Defrag one member and confirm db_total_size drops to approximately db_total_size_in_use; verify data integrity via hash checks (etcdctl endpoint hashkv across members). A possible explanation — not yet verified: The size growth is caused by bbolt's hashmap freelist reusing/merging free page spans less effectively than the array freelist for contiguous multi-page allocations, so under the same workload bbolt grows the file instead of reusing freed pages (Size up, SizeInUse flat). Since NoFreelistSync is true in both versions, the mechanism must be allocation behavior, not freelist persistence. This could be checked by: Run the same write workload on v3.5.27 twice, once with --backend-bbolt-freelist-type=array and once with map (defaults), and compare etcd_mvcc_db_total_size_in_bytes growth; additionally benchmark bbolt v1.3.x freelist.allocate() page-reuse behavior for both types. This analysis was produced with the assistance of an AI engineering system I created; I reviewed it before posting. |


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We recently upgraded our etcd clusters from
v3.4.34->v3.5.27and after the upgrade it has been observed that there has been significantly increase in etcd'stotalDBSizewhereastotalDBSizeInUseremains stable.The magnitude varies per cluster but the pattern is consistent across all of our etcd clusters.
Etcd v3.5.x has changed the default value of
--backend-bbolt-freelist-typefromarray(persisted to disk) tomap(in-memory). and because of this bolt-db is using hashmap to maintain the freelist, I suspect this to be the root cause of this issue.Questions:
v3.5.x?On the claim that "map freelist type has much better performance than array.", Has this been validated via perf testing for clusters running with a quota of
8–10 GiB? from this blog: https://www.cncf.io/blog/2019/05/09/performance-optimization-of-etcd-in-web-scale-data-scenario/ when this hashmap approach was introduced what I can understand that this hashmap based freelist was introduce for large-database scenarios. It is not clear that the performance benefit carries over to the small databases typical in most Kubernetes deployments.Is there any other feature/changes can cause this issue ?
All reactions