Switch to json-iterator for v1 api.

This makes queries ~15% faster and cuts cpu
time spent on json encoding by ~40%.
This commit is contained in:
Brian Brazil 2017-12-02 13:52:59 +00:00
parent 8ede14b24c
commit 299b78a887

View file

@ -15,7 +15,6 @@ package v1
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"math" "math"
@ -28,6 +27,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/json-iterator/go"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"github.com/prometheus/common/route" "github.com/prometheus/common/route"
"github.com/prometheus/tsdb" "github.com/prometheus/tsdb"
@ -754,6 +754,7 @@ func respond(w http.ResponseWriter, data interface{}) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
json := jsoniter.ConfigCompatibleWithStandardLibrary
b, err := json.Marshal(&response{ b, err := json.Marshal(&response{
Status: statusSuccess, Status: statusSuccess,
Data: data, Data: data,
@ -782,6 +783,7 @@ func respondError(w http.ResponseWriter, apiErr *apiError, data interface{}) {
} }
w.WriteHeader(code) w.WriteHeader(code)
json := jsoniter.ConfigCompatibleWithStandardLibrary
b, err := json.Marshal(&response{ b, err := json.Marshal(&response{
Status: statusError, Status: statusError,
ErrorType: apiErr.typ, ErrorType: apiErr.typ,