VictoriaMetrics/app/vmalert/datasource/testdata/instant_response.json

1 line
86 KiB
JSON
Raw Normal View History

app/vmalert: update parsing for instant responses (#6859) This change is made in attempt to reduce memory usage by vmalert when parsing big instant responses from VM/Prometheus. In https://github.com/VictoriaMetrics/VictoriaMetrics/commit/a5c427bac4102c53d1ea2aefe0b0e6872120ba9c vmalert switched from std json lib to fastjson lib in order to reduce amount of allocations, as according to highloaded profiles of vmalert the CPU is mostly spent on GC. But switching to fastjson resulted into excessive memory usage for cases when vmalert has to parse long json lines, which usually happens when instant response contains many `metric` objects. In this change we do a mixed parsing: 1. Slice of `metric` objects is parsed with std lib to keep mem low 2. Each `metric` object is parsed with fastjson to reduce allocs The benchmark results are the following: ``` pkg: github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/datasource BenchmarkParsePrometheusResponse/Instant_std+fastjson-10 1760 668959 ns/op 280147 B/op 5781 allocs/op MBs allocated at heap: 493.078392 mallocs: 18655472 BenchmarkParsePrometheusResponse/Instant_fastjson-10 6109 198258 ns/op 172839 B/op 5548 allocs/op MBs allocated at heap: 1056.384464 mallocs: 34457184 BenchmarkParsePrometheusResponse/Instant_std-10 1287 950987 ns/op 451677 B/op 9619 allocs/op MBs allocated at heap: 580.802976 mallocs: 13351636 ``` The benchmark function code with mem measurement is available here https://gist.github.com/hagen1778/b9c3ca7f8ca7d6b21aec9777112c5810 The benchmark contains 3 results: 1. Instant_std+fastjson is the implementation in this change 2. Instant_fastjson-10 is the implementation from https://github.com/VictoriaMetrics/VictoriaMetrics/commit/a5c427bac4102c53d1ea2aefe0b0e6872120ba9c 3. BenchmarkParsePrometheusResponse/Instant_std-10 is implementation before https://github.com/VictoriaMetrics/VictoriaMetrics/commit/a5c427bac4102c53d1ea2aefe0b0e6872120ba9c According to these results, this new implementation is slower than previous, but faster than before switching to fastjson. It also has lower number of allocations and roughly the same memory allocation on heap with GC turned off. --------- Other changes: 1. rm BenchmarkMetrics as it doesn't measure anything 2. simplify BenchmarkParsePrometheusResponse into BenchmarkPromInstantUnmarshal ### Describe Your Changes Please provide a brief description of the changes you made. Be as specific as possible to help others understand the purpose and impact of your modifications. ### Checklist The following checks are **mandatory**: - [ ] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/). Signed-off-by: hagen1778 <roman@victoriametrics.com>
2024-08-22 15:36:11 +00:00
[{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"*/favicon.ico","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"0"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/debug/pprof/","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"78372"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/debug/pprof/cmdline","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"0"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/debug/pprof/default","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"47048"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/debug/pprof/mutex","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"15682"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/debug/pprof/profile","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"15642"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/debug/pprof/symbol","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"0"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/debug/pprof/trace","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"0"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/insert/{}/datadog/api/beta/sketches","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","protocol":"datadog","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"0"]},{"metric":{"__name__":"vm_http_requests_total","cluster":"sandbox","container":"vminsert","endpoint":"http","instance":"10.71.0.3:8480","job":"vminsert-benchmark-vm-cluster","namespace":"benchmark","path":"/insert/{}/datadog/api/v1/check_run","pod":"vminsert-benchmark-vm-cluster-b955964f8-m544p","prometheus":"monitoring/monitoring-vmagent","protocol":"datadog","service":"vminsert-benchmark-vm-cluster"},"value":[1715686833.987,"0"]},{"metric":{"__name__":"v