Closed brandond closed 4 years ago
@brandond When this is ready, can we also backport into 1.17, 1.18, and 1.19 ? Hosted Rancher will be needing this fix.
I've just added some before/after perf figures.
Just for the record, this was run against a RDS MySQL database that had grown out of control (~450GB) and while the compaction did not run as fast as it would on a clean database, it did not affect etcd client (k3s server) functionality.
Configuring mysql database connection pooling: maxIdleConns=2, maxOpenConns=10, connMaxLifetime=0s
Kine listening on tcp://0.0.0.0:2380
COMPACT deleted 1000 rows from 1000 revisions in 260.646311ms - compacted to 54507838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 209.451541ms - compacted to 54508838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 210.975307ms - compacted to 54509838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 209.147251ms - compacted to 54510838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 249.981449ms - compacted to 54511838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 408.709057ms - compacted to 54512838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 482.409274ms - compacted to 54513838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 216.395163ms - compacted to 54514838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 244.119247ms - compacted to 54515838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 421.660987ms - compacted to 54516838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 297.367336ms - compacted to 54517838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 237.869493ms - compacted to 54518838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 242.567905ms - compacted to 54519838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 371.445965ms - compacted to 54520838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 443.500974ms - compacted to 54521838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 221.708513ms - compacted to 54522838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 430.106759ms - compacted to 54523838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 514.208017ms - compacted to 54524838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.4346351s - compacted to 54525838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.24711466s - compacted to 54526838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.241122638s - compacted to 54527838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.352619799s - compacted to 54528838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.239903625s - compacted to 54529838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.25365536s - compacted to 54530838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.346442674s - compacted to 54531838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.195258922s - compacted to 54532838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.375034317s - compacted to 54533838/66353379
COMPACT deleted 1000 rows from 1000 revisions in 1.338638356s - compacted to 54534838/66353379
Adds additional indexes and a transaction-locked optimized native SQL compaction query that replaces the existing unlocked row-by-row compaction logic. Highly inspired by https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/storage/etcd3/compact.go
This results in a roughly 400x reduction in compaction time for postgres, 150x for mysql, and a 40x for sqlite. Most of this is due to reduced round-trips and throughput to the database - the current code retrieves, evaluates, and (potentially) deletes each row individually during compaction.
Also updates SQL drivers to fix transaction handling bugs:
This is related to https://github.com/rancher/k3s/issues/1311
Test cluster: k3s 1.19.3 - 1 server 1 agent - rancher 2.5 - artifactory-jcr app
Code from this PR:
Current code (with stats logging patch https://github.com/brandond/kine/commit/45327c4f0051297309ae1f8ea848e132a172eab7)