looking for some solutions? You are welcome.

SOLVED: Simple golang http rest service hangs under load

antonof:

I am trying to test how golang can handle big loads to compare it with our current applications made with Java.

What I did is a simple echo rest service like that (I am adding just the important parts of my code):

// Return default message for root routing
func Index(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
}

// Main function
func main() {

    router := mux.NewRouter() //.StrictSlash(true)
    router.HandleFunc("/", Index).Methods("GET")
    router.HandleFunc("/echo/{message}", echoHandler(calledServiceURL)).Methods("GET")

    log.Println("Running server....")

    log.Fatal(http.ListenAndServe(port, router))
}

I did a test by using ab tool and it worked well with -c 500 -n 500 but when I tried to test with a big load like this

ab -c 500 -n 50000 http://localhost:9596/echo/javier

The process works well for a couple of seconds but then seems it close the tcp connection as I receive the following error:

Benchmarking localhost (be patient)
apr_socket_recv: Connection reset by peer (54)
Total of 501 requests completed

Is is due to a OS limitations that my test reached or is it the limit that my golang app could handle?

Is there a better way to process requests and then avoid the program to close connections? (queue requests or something like that).

Thanks in advance J



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent