Handling Multiple Requests

Hi All

Wanted to ask how many simultaneous connection requests can a server written this way handle?
Or do I have to use select or spawn threads to ensure that the server can handle simultaneous requests/connections? What I mean to ask is that if Go does something beneath the internal implementation in HandleFunc() to handle concurrent requests? Atleast in C you get to specify in listen() as to how many connections you can handle at a time for a socket.

func HandleRequests() {
myRouter := mux.NewRouter().StrictSlash(true)
log.Fatal(http.ListenAndServe(":3002", myRouter))

http.ListenAndServe gives each http request its own goroutine.

If you want a hard limit on the maximum number of active connections, it’s up to you to implement the limit and impose connection timeouts. The convenient ListenAndServe method is probably not suitable for a public Internet site because it doesn’t do any of that.

A max connections per host value may arrive in Go 1.8.


Hi Mathew

Thanks a lot. That provided me with some insight into the issue. Will see if I can go with http.Transport or how else to handle this.

As far as I can tell ListenAndServe* functions have a 3 minute timeout now and thus not leaking connections anymore. As for the ListenAndServe* methods of http.Server, they have always been usable.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.