Reputation: 23
This is what I used to do the test code
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"))
}
}
Here is the situation when the code runs
System is centos 6.5
This normal? If not normal, how to limit golang automatically create a large number of child processes?
Upvotes: 0
Views: 330
Reputation: 54353
Your htop
program is displaying threads, not processes. What you are seeing is Go's natural creation of threads which are used to run goroutines and to run system calls without blocking in the kernel.
You can control the number of threads created with the GOMAXPROCS environment variable.
Upvotes: 3