|
|
|
|
@ -3417,27 +3417,57 @@ func TestReturnAPIError(t *testing.T) { |
|
|
|
|
var testResponseWriter = httptest.ResponseRecorder{} |
|
|
|
|
|
|
|
|
|
func BenchmarkRespond(b *testing.B) { |
|
|
|
|
b.ReportAllocs() |
|
|
|
|
request, err := http.NewRequest(http.MethodGet, "/does-not-matter", nil) |
|
|
|
|
require.NoError(b, err) |
|
|
|
|
points := []promql.FPoint{} |
|
|
|
|
for i := 0; i < 10000; i++ { |
|
|
|
|
points = append(points, promql.FPoint{F: float64(i * 1000000), T: int64(i)}) |
|
|
|
|
} |
|
|
|
|
response := &QueryData{ |
|
|
|
|
ResultType: parser.ValueTypeMatrix, |
|
|
|
|
Result: promql.Matrix{ |
|
|
|
|
promql.Series{ |
|
|
|
|
Floats: points, |
|
|
|
|
Metric: labels.EmptyLabels(), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
matrix := promql.Matrix{} |
|
|
|
|
for i := 0; i < 1000; i++ { |
|
|
|
|
matrix = append(matrix, promql.Series{ |
|
|
|
|
Metric: labels.FromStrings("__name__", fmt.Sprintf("series%v", i), |
|
|
|
|
"label", fmt.Sprintf("series%v", i), |
|
|
|
|
"label2", fmt.Sprintf("series%v", i)), |
|
|
|
|
Floats: points[:10], |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
b.ResetTimer() |
|
|
|
|
api := API{} |
|
|
|
|
api.InstallCodec(JSONCodec{}) |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
api.respond(&testResponseWriter, request, response, nil) |
|
|
|
|
series := []labels.Labels{} |
|
|
|
|
for i := 0; i < 1000; i++ { |
|
|
|
|
series = append(series, labels.FromStrings("__name__", fmt.Sprintf("series%v", i), |
|
|
|
|
"label", fmt.Sprintf("series%v", i), |
|
|
|
|
"label2", fmt.Sprintf("series%v", i))) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cases := []struct { |
|
|
|
|
name string |
|
|
|
|
response interface{} |
|
|
|
|
}{ |
|
|
|
|
{name: "10000 points no labels", response: &QueryData{ |
|
|
|
|
ResultType: parser.ValueTypeMatrix, |
|
|
|
|
Result: promql.Matrix{ |
|
|
|
|
promql.Series{ |
|
|
|
|
Floats: points, |
|
|
|
|
Metric: labels.EmptyLabels(), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}}, |
|
|
|
|
{name: "1000 labels", response: series}, |
|
|
|
|
{name: "1000 series 10 points", response: &QueryData{ |
|
|
|
|
ResultType: parser.ValueTypeMatrix, |
|
|
|
|
Result: matrix, |
|
|
|
|
}}, |
|
|
|
|
} |
|
|
|
|
for _, c := range cases { |
|
|
|
|
b.Run(c.name, func(b *testing.B) { |
|
|
|
|
b.ReportAllocs() |
|
|
|
|
request, err := http.NewRequest(http.MethodGet, "/does-not-matter", nil) |
|
|
|
|
require.NoError(b, err) |
|
|
|
|
b.ResetTimer() |
|
|
|
|
api := API{} |
|
|
|
|
api.InstallCodec(JSONCodec{}) |
|
|
|
|
for n := 0; n < b.N; n++ { |
|
|
|
|
api.respond(&testResponseWriter, request, c.response, nil) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|