From 697fd441584eecd25c94efe7c8f26990d706e486 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 10 Nov 2020 16:11:16 +0200 Subject: [PATCH] lib/promscrape: make a copy of ScrapeWork from discovered []ScrapeWork slice instead of referring to an item in this slice This should prevent from holding previously discovered []ScrapeWork slices when a part of discovered targets changes over time. This should reduce memory usage for the case when big number of discovered scrape targets changes over time. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/825 --- docs/CHANGELOG.md | 2 ++ lib/promscrape/targetstatus.go | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 07b827338..f85c48a97 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,8 @@ # tip +* FEATURE: vmagent: reduce memory usage when service discovery detects big number of scrape targets and the set of discovered targets changes over time. + See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/825 * FEATURE: vmagent: add `-promscrape.dropOriginalLabels` command-line option, which can be used for reducing memory usage when scraping big number of targets. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/825#issuecomment-724308361 for details. * FEATURE: vmalert: explicitly set extra labels to alert entities. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/870 diff --git a/lib/promscrape/targetstatus.go b/lib/promscrape/targetstatus.go index cb4c8c0af..6479d581c 100644 --- a/lib/promscrape/targetstatus.go +++ b/lib/promscrape/targetstatus.go @@ -64,7 +64,7 @@ func (tsm *targetStatusMap) Reset() { func (tsm *targetStatusMap) Register(sw *ScrapeWork) { tsm.mu.Lock() tsm.m[sw.ID] = targetStatus{ - sw: sw, + sw: *sw, } tsm.mu.Unlock() } @@ -78,7 +78,7 @@ func (tsm *targetStatusMap) Unregister(sw *ScrapeWork) { func (tsm *targetStatusMap) Update(sw *ScrapeWork, group string, up bool, scrapeTime, scrapeDuration int64, err error) { tsm.mu.Lock() tsm.m[sw.ID] = targetStatus{ - sw: sw, + sw: *sw, up: up, scrapeGroup: group, scrapeTime: scrapeTime, @@ -221,7 +221,7 @@ type jobStatus struct { } type targetStatus struct { - sw *ScrapeWork + sw ScrapeWork up bool scrapeGroup string scrapeTime int64