add pprof
32
doc/DEV_DIARY.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Investigating a potential memory leak
|
||||
|
||||
## Date: 2/2/24
|
||||
### Hyphotesis: There's a memory leak happening
|
||||
### Signs: pprof/allocs
|
||||

|
||||
### Sumary
|
||||
|
||||
* Start the donut `make run`,
|
||||
* Check the general profiling http://localhost:6060/debug/pprof/?debug=1
|
||||
* Keep refreshing the page, notice that the counters: heap, goroutine, threadcreate are stable
|
||||
* Access the the demo http://localhost:8080/
|
||||
* Go back to the profiling page http://localhost:6060/debug/pprof/?debug=1
|
||||
* Notice that the prof counters are stable, regardless if you refresh multiple times
|
||||
* Now click on `[Connect]`
|
||||
* Observe how the perf counters go up http://localhost:6060/debug/pprof/?debug=1
|
||||
* Keep refreshing the http://localhost:6060/debug/pprof/? and you'll see that the counters `goroutine` and `threacreate` **are stable** but `heap` and `allocs` **counters are growing**.
|
||||
* You can check the specific heap page as well http://localhost:6060/debug/pprof/heap?debug=1
|
||||
* You can run the command `go tool pprof http://localhost:6060/debug/pprof/heap` and type `web`, it'll generate a svg tree map of heap.
|
||||
* Snapshot 1 at time `Start + 4 m`
|
||||
* 
|
||||
* Snapshot 2 at time `Start + 15 m`
|
||||
* 
|
||||
* Snapshot 2 at time `Start + 8 h`
|
||||
* 
|
||||
* Docker stats `docker stats` at `Start`
|
||||
* 
|
||||
* Docker stats `docker stats` at `Start + 10m`
|
||||
* 
|
||||
|
||||
> ref: https://go101.org/article/memory-leaking.html
|
||||
### Conclusion: there's not leak, I confused allocs growing nature.
|
2344
doc/imgs/entry_memory_leak/allocs_pprof001.svg
Normal file
After Width: | Height: | Size: 122 KiB |
BIN
doc/imgs/entry_memory_leak/docker_stats1.png.webp
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
doc/imgs/entry_memory_leak/docker_stats2.png.webp
Normal file
After Width: | Height: | Size: 33 KiB |
2283
doc/imgs/entry_memory_leak/goroutine_pprof001.svg
Normal file
After Width: | Height: | Size: 120 KiB |
1547
doc/imgs/entry_memory_leak/pprof001.svg
Normal file
After Width: | Height: | Size: 75 KiB |
1547
doc/imgs/entry_memory_leak/pprof002.svg
Normal file
After Width: | Height: | Size: 75 KiB |
1547
doc/imgs/entry_memory_leak/pprof003.svg
Normal file
After Width: | Height: | Size: 75 KiB |
@@ -11,6 +11,7 @@ services:
|
||||
- "8080:8080"
|
||||
- "8081:8081"
|
||||
- "8081:8081/udp"
|
||||
- "6060:6060"
|
||||
|
||||
srt:
|
||||
build:
|
||||
|
@@ -83,8 +83,9 @@ type StreamParameters struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
HTTPPort int32 `required:"true" default:"8080"`
|
||||
HTTPHost string `required:"true" default:"0.0.0.0"`
|
||||
HTTPPort int32 `required:"true" default:"8080"`
|
||||
HTTPHost string `required:"true" default:"0.0.0.0"`
|
||||
PproffHTTPPort int32 `required:"true" default:"6060"`
|
||||
|
||||
TCPICEPort int `required:"true" default:"8081"`
|
||||
UDPICEPort int `required:"true" default:"8081"`
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/flavioribeiro/donut/internal/entities"
|
||||
"go.uber.org/fx"
|
||||
@@ -30,6 +31,12 @@ func NewHTTPServer(
|
||||
log.Infow(fmt.Sprintf("Starting HTTP server. Open http://%s to access the demo", srv.Addr),
|
||||
"addr", srv.Addr,
|
||||
)
|
||||
// profiling server
|
||||
go func() {
|
||||
http.ListenAndServe(fmt.Sprintf(":%d", c.PproffHTTPPort), nil)
|
||||
}()
|
||||
|
||||
// main server
|
||||
go srv.Serve(ln)
|
||||
return nil
|
||||
},
|
||||
|