mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
85f60237e2
### Describe Your Changes Add support for https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6930 Calculate `-search.maxUniqueTimeseries` by `-search.maxConcurrentRequests` and remaining memory if it's **not set** or **less equal than 0**. The remaining memory is affected by `-memory.allowedPercent`, `-memory.allowedBytes` and cgroup memory limit. ### Checklist The following checks are **mandatory**: - [x] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/). --------- Signed-off-by: hagen1778 <roman@victoriametrics.com> Co-authored-by: Roman Khavronenko <roman@victoriametrics.com>
33 lines
794 B
Go
33 lines
794 B
Go
package servers
|
|
|
|
import (
|
|
"math"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
func TestCalculateMaxMetricsLimitByResource(t *testing.T) {
|
|
f := func(maxConcurrentRequest, remainingMemory, expect int) {
|
|
t.Helper()
|
|
maxMetricsLimit := calculateMaxUniqueTimeSeriesForResource(maxConcurrentRequest, remainingMemory)
|
|
if maxMetricsLimit != expect {
|
|
t.Fatalf("unexpected max metrics limit: got %d, want %d", maxMetricsLimit, expect)
|
|
}
|
|
}
|
|
|
|
// Skip when GOARCH=386
|
|
if runtime.GOARCH != "386" {
|
|
// 8 CPU & 32 GiB
|
|
f(16, int(math.Round(32*1024*1024*1024*0.4)), 4294967)
|
|
// 4 CPU & 32 GiB
|
|
f(8, int(math.Round(32*1024*1024*1024*0.4)), 8589934)
|
|
}
|
|
|
|
// 2 CPU & 4 GiB
|
|
f(4, int(math.Round(4*1024*1024*1024*0.4)), 2147483)
|
|
|
|
// other edge cases
|
|
f(0, int(math.Round(4*1024*1024*1024*0.4)), 2e9)
|
|
f(4, 0, 0)
|
|
|
|
}
|