VictoriaMetrics/lib/protoparser
Max Kotliar c05ffa906d
lib/promscrape: improve streamParse performance
Previously, performance of stream.Parse could be limited by mutex.Lock on callback function. It used shared writeContext. With complicated relabeling rules and any slowness at pushData function, it could significantly decrease parsed rows processing performance.

 This commit removes locks and makes parsed rows processing lock-free in the same manner as `stream.Parse` processing implemented at push ingestion processing.

 Implementation details:
- Removing global lock around stream.Parse callback.
- Using atomic operations for counters
- Creating write contexts per callback instead of sharing
- Improving series limit checking with sync.Once
- Optimizing labels hash calculation with buffer pooling
- Adding comprehensive tests for concurrency correctness

 Benchmark performance:
```
# before
BenchmarkScrapeWorkScrapeInternalStreamBigData-10             13          81973945 ns/op          37.68 MB/s    18947868 B/op        197 allocs/op

# after
goos: darwin
goarch: arm64
pkg: github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape
cpu: Apple M1 Pro
BenchmarkScrapeWorkScrapeInternalStreamBigData-10             74          15761331 ns/op         195.98 MB/s    15487399 B/op        148 allocs/op
PASS
ok      github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape       1.806s
```

Related issue:
 https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8159
---------
Signed-off-by: Maksim Kotlyar <kotlyar.maksim@gmail.com>
Co-authored-by: Roman Khavronenko <hagen1778@gmail.com>
2025-03-20 16:49:24 +01:00
..
csvimport lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
datadogsketches lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
datadogutils lib: consistently use regexp.Regexp.ReplaceAllLiteralString instead of regexp.Regexp.ReplaceAllString in places where the replacement cannot contain matching group placeholders 2024-07-17 12:41:54 +02:00
datadogv1 lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
datadogv2 lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
graphite lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
influx lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
native/stream lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
newrelic lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
opentelemetry lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
opentsdb lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
opentsdbhttp lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
prometheus lib/promscrape: improve streamParse performance 2025-03-20 16:49:24 +01:00
promremotewrite/stream lib/protoparser: substitute hybrid channel-based pools with plain sync.Pool 2024-04-20 21:59:51 +02:00
protoparserutil lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00
vmimport lib/protoparser: rename lib/protoparser/common to lib/protoparser/protoparserutil 2025-03-18 16:24:51 +01:00