我们有一个40 kb的json,它需要大约200毫秒。如果只是减少了json中的三个字段,大小减少到36 kb,但平均响应下降到125毫秒。我们在不想发送的字段中使用了json:“-”标记。我们使用
ctx.Status(fiber.StatusOK).JSON(model.GetEventListResponse{
Events: events,
NextPage: nextPage,
})
type GetEventListResponse struct {
NextPage string `json:"next_page"`
Events []Event `json:"events"`
}
type Event struct {
EventID int64 `json:"event_id"`
Currency int `json:"currency"`
EventName string `json:"event_name"`
Country string `json:"country"`
Place string `json:"place"`
EventFrom time.Time `json:"event_from"`
MainEventStart time.Time `json:"main_event_start"`
TotalParticipants int64 `json:"total_participants"`
TotalPool float64 `json:"total_pool"`
Laps int `json:"laps"`
TotalDistance float64 `json:"total_distance"`
SingleLapDistance float64 `json:"single_lap_distance"`
LapRecordTime time.Duration `json:"lap_record_time"`
LapRecordBy string `json:"lap_record_by"`
IsActive bool `json:"-"`
IsComplete bool `json:"-"`
Games []int64 `json:"-"`
}
字符串
事件数量为100。
JSON响应:-
{
"next_page": "Pw0hLnA......................KK1f8bc9LIY=",
"events": [
{
"event_id": 202312181540001,
"currency": 64,
"event_name": "Event39",
"country": "Country39",
"place": "Place39",
"event_from": "2023-12-12T15:09:02.619Z",
"main_event_start": "2023-12-12T15:09:02.619Z",
"total_participants": 292,
"total_pool": 1676.4006608884679,
"laps": 28,
"total_distance": 876.2850461295575,
"single_lap_distance": 8.119311404702122,
"lap_record_time": 54542000000000,
"lap_record_by": "Racer39"
},....}
}
型
1条答案
按热度按时间xmjla07d1#
你试过https://github.com/bytedance/sonic吗
我认为您需要编写基准测试,比较使用不同编码器的数据封送处理的性能