Update: Answered question with results from the web server hosted on VPS (Vultr)
I compared it against a NodeJS/Express server to achieve a point of comparison.
What have I done wrong?
Go server:
package main
import "github.com/gin-gonic/gin"
func main() {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
router.Run("0.0.0.0:9999")
}
Express Server:
const express = require('express')
const app = express()
app.get('/ping', (req, res) => res.send({ pong: 'pong' }))
app.listen(9999, () => console.log('Example app listening on port 9999!'))
Test
Tool was Vegeta
echo "GET http://localhost:9999/ping" | vegeta attack -rate=500 -duration=10s | vegeta report
Duration: 10s
Requests: 500 per s
Results
Go/Gin's Mean Response Time: 13000ms
Node/Express's Mean Response Time: 24ms
I put the test up on a VPS and compared their results. Looks like Go is king
5s @ 1000R/s
Node: [mean, 50, 95, 99, max] 611.524µs, 514.504µs, 768.853µs, 3.121218ms, 8.340432ms
[success rate] 100%
Go: [mean, 50, 95, 99, max] 485.536µs, 425.167µs, 803.236µs, 1.47899ms, 7.783679ms
[success rate] 100%
5s @ 2500R/s
Node: [mean, 50, 95, 99, max] 389.480416ms, 417.458353ms, 909.933675ms, 1.592021109s, 2.335314996s
[success rate] 60.22%
Go: [mean, 50, 95, 99, max] 223.248847ms, 217.48063ms, 376.252228ms, 436.460213ms, 636.40045ms
[success rate] 100%
5s @ 3750R/s
Node: [mean, 50, 95, 99, max] 321.055317ms, 132.748021ms, 1.174121791s, 1.66130059s, 2.381339843s
[success rate] 26.45%
Go: [mean, 50, 95, 99, max] 294.135919ms, 319.996625ms, 512.918987ms, 549.590029ms, 30.119526908s
[success rate] 78.42%
5s @ 5000kR/s
Node: [mean, 50, 95, 99, max] 632.77873ms, 614.378281ms, 1.108413609s, 1.505165854s, 2.156899637s
[success rate] 26.87%
Go: [mean, 50, 95, 99, max] 372.278943ms, 389.118423ms, 546.388561ms, 866.47292ms, 30.124971521s
[success rate] 46%
c.JSON(200, gin.H{
"message": "pong",
})
c.abort() // 请求输出后立即中断gin