0
我正在用fasthttp包构建Rest API。我有我使用来衡量性能的测试路线:Golang fasthttp请求很慢
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")
}
如果我发送这条路线需要10秒以上才能到println("HERE")
测试功能的请求。
我在Node.js
中构建了一个类似的端点,这个完全相同的功能和路线需要126毫秒。
为什么在这个世界中,只需要调用Go这个路径指向的函数就花了那么长时间?
我刚与确切的代码测试,它需要(1秒以下)几乎没有时间在到达'调用println( “HERE”)'。你设置你的测试有多难? –
尝试我的样品和帖子(添加评论)的代码(2)输出 –