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.