I propose to get acquainted with the decoding of the report of the end of 2019 by Alexander Valyalkin "Go optimizations in VictoriaMetrics"
VictoriaMetrics is a fast and scalable DBMS for storing and processing data in the form of a time series (a record forms time and a set of values ββcorresponding to this time, for example, obtained through periodic polling of sensor status or collection of metrics).
![](https://habrastorage.org/webt/a8/ua/hz/a8uahzgkj1ezyu0qiegqysypnls.png)
Slides
![](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.