gpt4 book ai didi

go - Go Prometheus客户端与Python Prometheus客户端获得不同的延迟

转载 作者:行者123 更新时间:2023-12-01 22:22:35 25 4
gpt4 key购买 nike

我正在阅读latency measurement codes,因为我发现测得的延迟高于python代码测得的端到端延迟。 以下InstrumentRoundTripperDuration用法正确吗? 我在互联网上找不到类似的示例。

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)


// metrics client
func NewClientMetrics(spec *v1.PredictorSpec, deploymentName string, modelName string) *ClientMetrics {
histogram := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: ClientRequestsMetricName,
Help: "A histogram of latencies for client calls from executor",
Buckets: prometheus.DefBuckets,
},
[]string{DeploymentNameMetric, PredictorNameMetric, PredictorVersionMetric, ServiceMetric, ModelNameMetric, ModelImageMetric, ModelVersionMetric, "method", "code"},
)

err := prometheus.Register(histogram)
if err != nil {
prometheus.Unregister(histogram)
prometheus.Register(histogram)
}
...

return &ClientMetrics{
ClientHandledHistogram: histogram,
Predictor: spec,
DeploymentName: deploymentName,
ModelName: modelName,
ImageName: imageName,
ImageVersion: imageVersion,
}
}

// In json rest client, construct metrics client
func NewJSONRestClient(protocol string, deploymentName string, predictor *v1.PredictorSpec, annotations map[string]string, options ...BytesRestClientOption) (client.SeldonApiClient, error) {

httpClient := http.DefaultClient
...

client := JSONRestClient{
httpClient,
logf.Log.WithName("JSONRestClient"),
protocol,
deploymentName,
predictor,
metric.NewClientMetrics(predictor, deploymentName, ""),
}
...

return &client, nil
}

// In Json rest client, create a function to measure roundtrip latency
func (smc *JSONRestClient) getMetricsRoundTripper(modelName string, service string) http.RoundTripper {
...
return promhttp.InstrumentRoundTripperDuration(smc.metrics.ClientHandledHistogram.MustCurryWith(prometheus.Labels{
metric.DeploymentNameMetric: smc.DeploymentName,
metric.PredictorNameMetric: smc.predictor.Name,
metric.PredictorVersionMetric: smc.predictor.Annotations["version"],
metric.ServiceMetric: service,
metric.ModelNameMetric: modelName,
metric.ModelImageMetric: imageName,
metric.ModelVersionMetric: imageVersion,
}), http.DefaultTransport)
}

// http call (getMetricsRoundTripper is called middleware)
client := smc.httpClient
client.Transport = smc.getMetricsRoundTripper(modelName, method)

源代码:

https://github.com/SeldonIO/seldon-core/blob/master/executor/api/rest/client.go#L88和第148、118行

https://github.com/SeldonIO/seldon-core/blob/master/executor/api/metric/client.go#L22

谢谢

最佳答案

Python prometheus客户端与go prometheus客户端具有不同的存储桶。
前者使用Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10}

但是后者正在使用[]float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}(code)。

他们使用的是不同的存储桶,因此指标可能看起来有所不同。

关于go - Go Prometheus客户端与Python Prometheus客户端获得不同的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62226089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com