duan02468 2019-07-02 15:06
浏览 93

从查询到c.JSON的速度非常慢

I'm querying my database using Gorm and then using gin's c.JSON to marshal the structs to json.

It's a large query with not so much result ( < 100k ) and i'm having an issue with the time it takes ( 6-10 seconds ) to marshal the data.

I have no idea where to start to resolve the issue.

    [2019-07-02 14:41:04]  [946.63ms]   SELECT  big slow query
    [62861 rows affected or returned ]
    [GIN] 2019/07/02 - 14:41:11 | 200 |   7.92347114s |  ip | GET      /api/date/2019-05-30


    [2019-07-02 14:40:44]  [660.47ms]   SELECT big slow query
    [7583 rows affected or returned ]
    [GIN] 2019/07/02 - 14:40:54 | 200 | 10.841096216s |  ip | GET      /api/dailies

    [2019-07-02 14:43:49]  [154.13ms]   SELECT simple query
    [11 rows affected or returned ]
    [GIN] 2019/07/02 - 14:43:49 | 200 |  158.256792ms |  ip | GET      /api/dailycount

As you can see query 1 and 2 resolve in 600-900 ms , it's slow but it can be optimised separately. The issue is that the response of the server take 7.9 and 10.8s ..! For the smaller query there isn't much difference but i'm not getting why this is happening.

The go code for one of the route is pretty straightforward and similare for all routes :

    var alertList []AlertJson
    dbInstance.Debug().Raw("SELECT big query").Scan(&alertList)
    c.JSON(http.StatusOK, gin.H{"alerts": alertList}) 

10.2 second for the second query with 7583rows to marshal seem pretty insane to me.

  • 写回答

1条回答 默认 最新

  • dongshadu4498 2019-07-04 14:37
    关注

    There was immense lag on my server provider and just in fact the 10 second is indeed the delay for me to receive the data as mentioned by peter.

    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端