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).

Slides

. β . GitHub . Go . . fast, quick .
VictoriaMetrics. ? .

:
- , VictoriaMetrics.
- , .
- , .
- : .
- , VictoriaMetrics. bitset- Go.

VictoriaMetrics - ? , . . , β . ClickHouse, ClickHouse. , , : MergeTree, , .
VictoriaMetrics .
β . . , . VictoriaMetrics .
VictoriaMetrics β . . VictoriaMetrics, .
, VictoriaMetrics , . Go, .

, ? . β (timestamp, ), . β float64.
. ? -.
. : __name__="cpu_usage" β , instance="my-server" β , , datacenter="us-east" β , .
, -. (timestamp, value). t1, t3, t3, ..., tN β timestamps, 10, 20, 12, ..., 15 β . cpu-usage .

? - ?
- DevOps CPU, RAM, , rps, . .
- IoT β , geo coordinates -.
- β .
- , . , VictoriaMetrics , .
- . , ; ; , ; . .
- . , . .
- Healthcare β , ..
, , , , , , . .

? ?
, . . (timestamp, value) . API , -, , regexp. , , .
, SQL . , SQL , . , PromQL, InfluxQL, Flux, Q. , - . PromQL, , . Prometheus.

VictoriaMetrics.
. . .
, , label=value . .
- TSDB, . timeseries_ids , label=value. , timeseries_ids.

, select-.
- timeseries_ids,- label=value, .
- data points timeseries_ids.
- - data points, . .
. timeseries_ids . VictoriaMetrics, , :)

. , . , ? , . , .
. , . ? label=value, label value β . β timeseries_ids, label=value.
timeseries_ids, label=value.
timeseries_ids label=value, label=regexp. ? timeseries_ids label=value.

. . .
getMetricIDs . label=value. metricIDs.
? , invertedIndex. (map), slice int-. label=value.
: metricIDs label=value, label=value, metricIDs . intersectInts, . .

, . . ? , . . . .
. . , , β out of memory error. .

, 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.

, Go. . LevelDB.
, . . , map . label=value. label=value metricIDs . .

, . 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 β :)

. mergeset.
Mergeset MergeTree. ClickHouse. , mergeset timeseries_ids . Mergeset Go. VictoriaMetrics GitHub. mergeset /lib/mergeset. , .
API mergeset LevelDB RocksDB. . . .

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 .

high churn rate. - high churn rate production? .
, Kubernetes, deployment, . . . Kubernetes - idβ deployment' label.
? , deployment' , deployment_id. .
, , , , , . β high churn rate.
high churn rate , - . .

? . . . . - , . . , .
, . , , id .
, , . . . , , .

. id , .
, , . .
, . VictoriaMetrics . . , . - , partition , , . . . VictoriaMetrics , . , .
. , timeseries_ids , , .

? β . . . label=value, . timeseries_ids .
. N , , , . id .
10 . , label=value N . , labels , Kubernetes.

β . . key=value . . . , . , . . . , ClickHouse. .

β timeseries_ids. , . timeseries_ids label=value.

β . . intersectInts slices β a b. slices.
. slice a, slice b. . , , . result.

? β . , slice a b , . , .

map. map. map slice a. slice b. β slice b map. , .

? , . . . slices. slice 2 , , .
, , map.
β overhead . . , VictoriaMetrics intersection map. , map map.
? Go . . . hash , HashMap. hashβ . VictoriaMetrics.

bitset, . slices. bitset. slice. slice. . . . . , map add has.

, , map, - , , 10 , map VictoriaMetrics.
, map. .
, , .
, β , . . . , ids VictoriaMetrics. , . , , out of memory error .

. , VictoriaMetrics, lib/uint64set. VictoriaMetrics, timeseries_id 64- , 32 32 .
, .

API. . API VictoriaMetrics. . . . , VictoriaMetrics.
add, . has, . del, . len, . clone . appendto slice timeseries_ids.

. 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- .

, .
uint64 . 32 , 32 . buckets. 32 bucket . , add b32 buckets. 32 . true, , . false, . .
bucket hi-, addAlloc, bucket, bucket-.

b32.add. . 16 , 16 .
16 . . add, bucket16.

, . uint64 id slice bit, bitmask. 64- , , . , , . , ids 10 maps.

VictoriaMetrics . , production.
β , , , , . . production, . , VictoriaMetrics , .

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.