笔记本(英特尔 i7 8700HQ),分配内存4G, 4核CPU虚拟机进行试验
1、Ginfunc main() {
router := gin.New()
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
server := &http.Server{
Addr: addr,
WriteTimeout: time.Second * 3,
Handler: router,
}
log.Fatal(server.ListenAndServe())
}
c10k+100w
var addr = "127.0.0.1:2003"
func main() {
log.Println("Starting httpserver at " + addr)
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
upath := fmt.Sprintf("http://%s%s\n", r.Addr, req.URL.Path)
realIP := fmt.Sprintf("RemoteAddr=%s,X-Forwarded-For=%v,X-Real-Ip=%v\n", req.RemoteAddr, req.Header.Get("X-Forwarded-For"), req.Header.Get("X-Real-Ip"))
header := fmt.Sprintf("headers =%v\n", req.Header)
io.WriteString(w, upath)
io.WriteString(w, realIP)
io.WriteString(w, header)
})
server := &http.Server{
Addr: addr,
WriteTimeout: time.Second * 3,
Handler: mux,
}
log.Fatal(server.ListenAndServe())
}
3、ReverseProxy
var realAddr, proxyAddr = "http://127.0.0.1:2003", "127.0.0.1:8080"
func main() {
backend, _ := url.Parse(realAddr)
server := http.Server{
Addr: proxyAddr,
WriteTimeout: time.Second * 3,
Handler: httputil.NewSingleHostReverseProxy(backend),
}
log.Fatal(server.ListenAndServe())
}
4、Nginx代理
user root;
worker_processes 16;
events {
worker_connections 65535 ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 20030;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:2003/;
}
}
}
5、汇总表格
方式 | 类别 | QPS | total | time | |
---|---|---|---|---|---|
http服务 | c10k+100w | gin | 10444 | 100w | 95.741s |
http服务 | 线程30、600个连接持续30秒 | gin | 60684 | 183w | 30.10s |
http服务 | 线程30、600个连接持续30秒 | go http | 44583 | 134w | 30.10s |
http代理 | 线程30、600个连接持续30秒 | ReverseProxy | 27313 | 82.2w | 30.10s |
http代理 | 线程30、600个连接持续30秒 | Nginx | 15162 | 45.6w | 30.10s |
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)