我建议熟悉Alexander Valyalkin的“ VictoriaMetrics中的优化”对2019年底报告的解码
VictoriaMetrics是一种快速且可扩展的数据库管理系统,用于以时间序列的形式存储和处理数据(记录形成时间以及与此时间对应的一组值,例如,通过定期轮询传感器状态或收集度量值获得)。
![](https://habrastorage.org/webt/a8/ua/hz/a8uahzgkj1ezyu0qiegqysypnls.png)
滑梯
![](https://habrastorage.org/webt/8m/wd/k2/8mwdk2k-7ks6a5bml4u2yao7zzq.png)
. – . GitHub . Go . . fast
, quick
.
VictoriaMetrics. ? .
![](https://habrastorage.org/webt/z6/x0/g3/z6x0g3th4zzzylpolm60bsfqxdu.png)
:
- , VictoriaMetrics.
- , .
- , .
- : .
- , VictoriaMetrics. bitset- Go.
![](https://habrastorage.org/webt/xo/yu/wf/xoyuwfsgtrs-aoqx1d7exrfthcw.png)
VictoriaMetrics - ? , . . , – . ClickHouse, ClickHouse. , , : MergeTree, , .
VictoriaMetrics .
— . . , . VictoriaMetrics .
VictoriaMetrics — . . VictoriaMetrics, .
, VictoriaMetrics , . Go, .
![](https://habrastorage.org/webt/ta/ux/wg/tauxwgc2bngokx6meub0bsw46w8.png)
, ? . — (timestamp, )
, . – float64.
. ? -.
. : __name__="cpu_usage"
– , instance="my-server"
— , , datacenter="us-east"
— , .
, -. (timestamp, value)
. t1, t3, t3, ..., tN
— timestamps, 10, 20, 12, ..., 15
— . cpu-usage .
![](https://habrastorage.org/webt/av/jp/2n/avjp2nl6qfh9u4ltsxdntkeachc.png)
? - ?
- DevOps CPU, RAM, , rps, . .
- IoT – , geo coordinates -.
- – .
- , . , VictoriaMetrics , .
- . , ; ; , ; . .
- . , . .
- Healthcare – , ..
, , , , , , . .
![](https://habrastorage.org/webt/vx/rg/gn/vxrggn2eqb_sf1p-q85xr1g3xdg.png)
? ?
, . . (timestamp, value)
. API , -, , regexp. , , .
, SQL . , SQL , . , PromQL, InfluxQL, Flux, Q. , - . PromQL, , . Prometheus.
![](https://habrastorage.org/webt/hl/g7/a0/hlg7a02gquoqb9xku3ynmbhr9d0.png)
VictoriaMetrics.
. . .
, , label=value
. .
- TSDB, . timeseries_ids
, label=value
. , timeseries_ids
.
![](https://habrastorage.org/webt/13/jn/v7/13jnv7nyijhaymi0olcvkdeuf-s.png)
, select-.
timeseries_ids
, label=value
, .- data points
timeseries_ids
. - - data points, . .
. timeseries_ids
. VictoriaMetrics, , :)
![](https://habrastorage.org/webt/vg/6o/ig/vg6oighnetd3sfv22srzz6azu6k.png)
. , . , ? , . , .
. , . ? label=value
, label
value
— . – timeseries_ids
, label=value
.
timeseries_ids
, label=value
.
timeseries_ids
label=value
, label=regexp
. ? timeseries_ids
label=value
.
![](https://habrastorage.org/webt/or/6i/3q/or6i3q-m3bhqomcofrb7dk0co1y.png)
. . .
getMetricIDs
. label=value
. metricIDs
.
? , invertedIndex
. (map
), slice int-. label=value
.
: metricIDs
label=value
, label=value
, metricIDs
. intersectInts
, . .
![](https://habrastorage.org/webt/46/jm/hz/46jmhzn4yky5ea_nfznx__swyru.png)
, . . ? , . . . .
. . , , – out of memory error. .
![](https://habrastorage.org/webt/mp/sp/1d/mpsp1dsehfavabbej5ml7djgcng.png)
, LevelDB, RocksDB.
, , .
LevelDB RocksDB – Google Facebook. LevelDB. Facebook LevelDB , RocksDB. RocksDB Facebook , RocksDB MySQL. MyRocks.
LevelDB. ? label=value
. – , label=value
.
c label=value
, timeseries_ids
. timeseries_ids
, label=prefix
, range scan, . . . , label=prefix
timeseries_ids
.
![](https://habrastorage.org/webt/os/0b/el/os0belq1vsrju4ebdhlgtcfmypg.png)
, Go. . LevelDB.
, . . , map
. label=value
. label=value
metricIDs . .
![](https://habrastorage.org/webt/7u/cq/5o/7ucq5omzldvhbpn1fwpbumvd0j8.png)
, . VictoriaMetrics LevelDB. .
? LevelDB , . slice metricIDs
. — slice .
LevelDB GetValues
, label=value
. timeseries_ids
. timeseries_ids
slice timeseries_ids
. , , map' .
, LevelDB C. C- Go . . , , go, 1-5 , . VictoriaMetrics – :)
![](https://habrastorage.org/webt/lc/_c/sw/lc_csw07os6wcpc8jyvla39pk5w.png)
. mergeset.
Mergeset MergeTree. ClickHouse. , mergeset timeseries_ids
. Mergeset Go. VictoriaMetrics GitHub. mergeset /lib/mergeset. , .
API mergeset LevelDB RocksDB. . . .
![](https://habrastorage.org/webt/j0/-l/mo/j0-lmotkgyw_rg-at2dopsk7e74.png)
mergeset . , VictoriaMetrics production .
?
– high churn rate. – . , . .
– . , , . , , , . 4 . , , 100 400 . .
, . , , . 40 , , , 40 .
. , idle, . user space, kernel space . , . 7-8 .
40 8 = 320 . 100, 32 000 400.
Kubernetes. , Kubernetes . Kubernetes . . deployment . . , high-cardinality. VictoriaMetrics .
![](https://habrastorage.org/webt/jn/u8/8x/jnu88xu0opegwjjghubewiyq8xk.png)
high churn rate. - high churn rate production? .
, Kubernetes, deployment
, . . . Kubernetes - id’ deployment' label.
? , deployment' , deployment_id
. .
, , , , , . – high churn rate.
high churn rate , - . .
![](https://habrastorage.org/webt/yn/tn/7-/yntn7-crolkneezzzqqp7ez1lak.png)
? . . . . - , . . , .
, . , , id .
, , . . . , , .
![](https://habrastorage.org/webt/uy/yb/xx/uyybxxbjvedganmy_y6cpb_cqr4.png)
. id , .
, , . .
, . VictoriaMetrics . . , . - , partition , , . . . VictoriaMetrics , . , .
. , timeseries_ids
, , .
![](https://habrastorage.org/webt/--/a8/jq/--a8jqa82xqvnozcauydt12y6y4.png)
? – . . . label=value
, . timeseries_ids
.
. N , , , . id .
10 . , label=value
N . , labels , Kubernetes.
![](https://habrastorage.org/webt/et/xz/fq/etxzfqr5q9ypgf_det_z_rcbhem.png)
– . . key=value
. . . , . , . . . , ClickHouse. .
![](https://habrastorage.org/webt/v6/me/yu/v6meyus-znzr09ej6yph4f64bc4.png)
– timeseries_ids
. , . timeseries_ids
label=value
.
![](https://habrastorage.org/webt/f5/mw/x6/f5mwx6uxaksryzqajhrvqlqmdrm.png)
– . . intersectInts
slices — a
b
. slices.
. slice a
, slice b
. . , , . result
.
![](https://habrastorage.org/webt/z_/fv/v7/z_fvv7xrf2hff-qsbkeqm1zbzcw.png)
? — . , slice a
b
, . , .
![](https://habrastorage.org/webt/9j/yj/-c/9jyj-cdn6kppt-opngjo_jjgday.png)
map. map. map slice a
. slice b
. – slice b
map. , .
![](https://habrastorage.org/webt/y8/zg/2i/y8zg2ifmtrfkhovyhbzq8_v6lqs.png)
? , . . . slices. slice 2 , , .
, , map.
– overhead . . , VictoriaMetrics intersection map. , map map.
? Go . . . hash , HashMap. hash’ . VictoriaMetrics.
![](https://habrastorage.org/webt/q7/da/iv/q7daivrlao2ivquuumz6yzh8w1s.png)
bitset, . slices. bitset. slice. slice. . . . . , map add
has
.
![](https://habrastorage.org/webt/ra/r-/xb/rar-xbesf3yq7pmt8fiqqwlms7k.png)
, , map, - , , 10 , map VictoriaMetrics.
, map. .
, , .
, – , . . . , ids VictoriaMetrics. , . , , out of memory error .
![](https://habrastorage.org/webt/eh/qw/11/ehqw11vht8nqkuvtqfg4vh1rure.png)
. , VictoriaMetrics, lib/uint64set. VictoriaMetrics, timeseries_id
64- , 32 32 .
, .
![](https://habrastorage.org/webt/ou/5e/ik/ou5eik1fmavrysmoqzerbjh6qhk.png)
API. . API VictoriaMetrics. . . . , VictoriaMetrics.
add
, . has
, . del
, . len
, . clone
. appendto
slice timeseries_ids
.
![](https://habrastorage.org/webt/cs/zo/g8/cszog8jpbuijmvgvzpoqsas4gcy.png)
. set :
ItemsCount
– , set. , , VictoriaMetrics bitset.
– buckets
. slice bucket32
. hi
. 32 . slice — b16his
buckets
bucket16
.
16 64- . bitsets 16 .
Bucket64
uint64
. . bucket16
2^16=65536
. 8, 8 . 8, 1000 uint64
. . . Bucket16
– 8- .
![](https://habrastorage.org/webt/ve/kw/p0/vekwp0pi-suxonq7o6cluhibigk.png)
, .
uint64
. 32 , 32 . buckets
. 32 bucket . , add
b32 buckets
. 32 . true
, , . false
, . .
bucket
hi-, addAlloc
, bucket
, bucket-.
![](https://habrastorage.org/webt/rl/g4/7i/rlg47ibsxvxtsef-b7xgl3jceym.png)
b32.add
. . 16 , 16 .
16 . . add, bucket16
.
![](https://habrastorage.org/webt/hv/j6/zc/hvj6zchagd_6ujzwa97p2bncbt0.png)
, . uint64
id slice bit, bitmask
. 64- , , . , , . , ids 10 maps.
![](https://habrastorage.org/webt/xl/g_/ez/xlg_ezzq-y_qagmmkzwawnor4sg.png)
VictoriaMetrics . , production.
– , , , , . . production, . , VictoriaMetrics , .
![](https://habrastorage.org/webt/tb/un/om/tbunom334y_4nk6zkfyck-tdt_u.png)
bitset. C++ vector bool, bitset. ?
, . bitset ids timeseries, VictoriaMetrics. , 32 . 32 . , . . C++ , , . , , .
. - ClickHouse . , C++ - . , , , , 32 .
. InfluxDB?
. , InfluxDB 10 high cardinality , , , . , VictoriaMetrics 1 GB , InfluxDB 10 Gb. .
, InfluxDB – Flux InfluxQL. PromQL, VictoriaMetrics. PromQL – Prometheus.
– , InfluxDB , fields . . . .
VictoriaMetrics . -. – – (timestamp, value)
, – label=value
. fields measurements. , , , , , InfluxDB, , . , , .
. , - , , , ?
Go' map'. , , , . . , .
! ! . Wildberries. . . , , , , , , , . . , - ? 2 — bitset , , , ? , ?
. . , . , ?
. , . , .
. , , . churn rate , . . , .
– , – . Prometheus . Prometheus . , - label timeseries. , , , , VictoriaMetrics. VictoriaMetrics , - , .
, , . timeseries-, . . – intersect . , , .
?
.
LevelDB mergeset . . ? – . , . – 5 . 100 000 000 , , .
, . . , , . ? - VictoriaMetrics, ClickHouse . ., ?
, . , ? , , , – . . . . .
, . . , , . , , - ClickHouse , , , . , - , , , ? , , .
, . , Prometheus recording rules. . . , , . VictoriaMetrics , Prometheus, recoding rules.
, . , Go, . . . , . , - . , , . , ClickHouse timeseries-, .
. , , - Graphite Carbon. , . . , . . , , , , , . Prometheus, VictoriaMetrics . ? , ?
. . , (downsampling). . -, downsampling
- : - , - , , . , . , . .
– , VictoriaMetrics, ClickHouse, , , , . VictoriaMetrics – 50 000 000 . . . . 20 , , . VictoriaMetrics ClickHouse downsamling.
, VictoriaMetrics . production 0,4 0,8 . – timestamp + . , .
. . ?
. . – . Graphite, , . OpenTSDB . InfluxDB – . VictoriaMetrics – , Prometheus . VictoriaMetrics remote storage Prometheus . .
, , , — , , . DevOps- , 30 , , , . high frequency trading systems, .
VictoriaMetrics DevOps-, , . , – high frequency trading systems.
! . PromQL?
. VictoriaMetrics PromQL. PromQL, MetricsQL. YouTube. Monitoring Meetup .
Telegram VictoriaMetrics.