我的 http 响应性能很慢
使用 Go 和 Fasthttp
package main
import (
"fmt"
"github.com/valyala/fasthttp"
)
func fastHTTPHandler(ctx *fasthttp.RequestCtx) {
var s string = ""
for i := 1; i <= 100000; i++ {
s += "hello "
}
ctx.SetBodyString(s)
}
func main() {
fmt.Print("Started")
fasthttp.ListenAndServe(":8081", fastHTTPHandler)
}
并在 Insomnia (Postman) 中进行测试。执行时间 3-4 秒。PHP 上的类似代码在 900 毫秒内执行。