We have a simple http server that responds to POST requests. Normally it's running without any issues, but recently we decided to add in additional component for request analysis.
Currently it's as follows:
func handleRequest(response http.ResponseWriter, request *http.Request) {
if request.Method != "POST" {
response.Write([]byte("Only POST"))
return
}
body, err := ioutil.ReadAll(request.Body)
request.Body.Close()
val := generateResponse(body)
response.Write(val)
}
Normally the response time for this is around 40-50ms. Server usage at around 25%-30%.
With analysis tool added, the response time somehow increases even though it's on a separate routine.
func handleRequest(response http.ResponseWriter, request *http.Request) {
if request.Method != "POST" {
response.Write([]byte("Only POST"))
return
}
body, err := ioutil.ReadAll(request.Body)
request.Body.Close()
val := generateResponse(body)
response.Write(val)
go doAnalysis(val)
}
Server usage is slightly higher at around 35%-40% due to additional processing. The response time is around 70-90ms now. Shouldn't spawning off a go-routine result in similar response time since response is written already?