[英]Why in Linux, golang run Http service will automatically create multiple child processes?
这就是我用来做测试代码的
package main
import (
"net/http"
"time"
)
func main() {
s := &http.Server{
Addr: ":9301",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
http.HandleFunc("/line/getList", Response)
s.ListenAndServe()
}
func Response(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Connection", "keep-alive")
w.WriteHeader(200)
for i:= 0; i < 10000; i++ {
w.Write([]byte("hello world"))
}
}
这是代码运行时的情况
系统是centos 6.5
这正常吗? 如果不正常,如何限制golang自动创建大量子进程?
您的htop
程序正在显示线程,而不是进程。 您将看到Go自然地创建了线程,这些线程用于运行goroutine和运行系统调用,而不会阻塞内核。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.