dimanche 28 juin 2015

Go web server requests spawn its own goroutine?

I want to know how exactly goroutine and go web server works whenever requests come in:

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

In this code,

  1. Every request to / calls the handler. Does this mean each request spawns its own goroutine? Or does it spawns its own process or thread? Is there any documentation on how those requests get its own goroutine?

  2. How do other languages handle this request? For example, does Python flask launch its own process for each request?

Thanks,




Aucun commentaire:

Enregistrer un commentaire