Fix memory leak in server

Remove server instrumentation
This commit is contained in:
2024-06-27 11:16:25 +02:00
parent 4ca3053243
commit 51a94b6636
3 changed files with 47 additions and 22 deletions

View File

@@ -44,10 +44,32 @@ func handleDownload(responseWriter http.ResponseWriter, request *http.Request) {
}
func init() {
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
// log.SetFlags(log.Lmicroseconds | log.Lshortfile)
log.SetFlags(log.Lmicroseconds)
}
// Mainly used to detect memory leaks
// func instrument() {
// numGoroutines := runtime.NumGoroutine()
// var m runtime.MemStats
// runtime.ReadMemStats(&m)
// malloc := float64(m.Alloc)
// ramUsedMB := malloc / 1024 / 1024
// kbPerGoroutine := malloc / 1024 / float64(numGoroutines)
// log.Printf("Number of active goroutines: %d; RAM used: %.2f MB; KB per goroutine: %.2f", numGoroutines, ramUsedMB, kbPerGoroutine)
// }
func main() {
// go func() {
// for {
// time.Sleep(1 * time.Second)
// instrument()
// }
// }()
http.HandleFunc("/ws", wsHandler)
http.HandleFunc("/download", handleDownload)
log.Println("Server starting on :8080")