VictoriaMetrics/lib/promscrape
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
..
discovery spelling and grammar fixes via codespell () 2025-03-17 16:32:10 +01:00
discoveryutils lib/promrelabel/scrape_url: properly parse IPv6 address from __address__ label 2025-02-28 14:19:10 +04:00
testdata lib/promscrape: disable support for service discovery and metrics scrape via http2 2023-07-06 16:03:37 -07:00
client.go lib/promscrape: fixed reload on max_scrape_size change () 2024-10-18 11:35:23 +02:00
client_test.go spelling and grammar fixes via codespell () 2025-03-17 16:32:10 +01:00
config.go lib/promutils: move time-related funcs from promutils to timeutil () 2025-03-03 10:25:42 +01:00
config_test.go lib/promscrape: add relabel configs to global section 2024-10-31 19:58:22 +01:00
config_timing_test.go lib/promscrape: optimize service discovery speed 2022-11-29 21:26:00 -08:00
relabel_debug.go app/vmselect: small cleanup after 4f3f9950d0 2023-05-08 14:57:11 -07:00
scraper.go lib/promscrape: add Marathon service discovery 2025-01-08 18:57:22 +01:00
scraper_test.go lib/promscrape: fixed reload on max_scrape_size change () 2024-10-18 11:35:23 +02:00
scrapework.go lib/promscrape: improve streamParse performance 2025-03-20 16:49:24 +01:00
scrapework_test.go lib/promscrape: improve streamParse performance 2025-03-20 16:49:24 +01:00
scrapework_timing_test.go lib/promscrape: improve streamParse performance 2025-03-20 16:49:24 +01:00
targetstatus.go spelling and grammar fixes via codespell () 2025-03-17 16:32:10 +01:00
targetstatus.qtpl lib/promscrape: follow-up for 1e83598be3 2024-07-16 12:38:21 +02:00
targetstatus.qtpl.go lib/promscrape: follow-up for 1e83598be3 2024-07-16 12:38:21 +02:00