Middle
The service started responding in 3 seconds instead of 100 milliseconds. What would you do first?
sobes.tech AI
Answer from AI
First of all, you need to gather diagnostic data:
- Check service logs for errors or warnings.
- Measure the execution time of key operations (profiling).
- Check CPU, memory, network, and database load.
- See if external dependencies (e.g., database, third-party services) have changed.
Next, you can use profilers (pprof in Go) to identify bottlenecks. There may be locks, long database queries, or memory leaks.
Example of running pprof:
import (
"net/http"
_ "net/http/pprof"
)
func main() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
// other code
}
After collecting data, analyze and optimize problematic areas.