I am building a Rest API with fasthttp package. I have a test route that I am using to measure performance:
package main
import (
"github.com/valyala/fasthttp"
"runtime"
)
func main() {
runtime.GOMAXPROCS(8)
m := func(ctx *fasthttp.RequestCtx) {
switch string(ctx.Path()) {
case "/test":
test(ctx)
default:
ctx.Error("not found", fasthttp.StatusNotFound)
}
}
fasthttp.ListenAndServe(":80", m)
}
func test(ctx *fasthttp.RequestCtx) {
println("HERE")
}
If I send a request to this route it takes over 10 seconds to get to the println("HERE")
in the test function.
I have built a comparable endpoint in Node.js
and this exact same function and route takes 126 milliseconds.
Why in the world does it take so long just to call the function that this route points to in Go?