add pprof

This commit is contained in:
Leandro Moreira
2024-02-03 09:35:57 -03:00
parent 36db07ff7c
commit cf63b8e144
11 changed files with 9311 additions and 2 deletions

32
doc/DEV_DIARY.md Normal file
View File

@@ -0,0 +1,32 @@
# Investigating a potential memory leak
## Date: 2/2/24
### Hyphotesis: There's a memory leak happening
### Signs: pprof/allocs
![allocs profile print screen 1](imgs/entry_memory_leak/allocs_pprof001.svg "allocs profile print screen 1")
### 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`
* ![heap profile print screen 1](imgs/entry_memory_leak/pprof001.svg "heap profile print screen 1")
* Snapshot 2 at time `Start + 15 m`
* ![heap profile print screen 2](imgs/entry_memory_leak/pprof002.svg "heap profile print screen 2")
* Snapshot 2 at time `Start + 8 h`
* ![heap profile print screen 3](imgs/entry_memory_leak/pprof003.svg "heap profile print screen 3")
* Docker stats `docker stats` at `Start`
* ![docker stats print screen 1](imgs/entry_memory_leak/docker_stats1.png.webp "docker stats print screen 1")
* Docker stats `docker stats` at `Start + 10m`
* ![docker stats print screen 2](imgs/entry_memory_leak/docker_stats2.png.webp "docker stats print screen 2")
> ref: https://go101.org/article/memory-leaking.html
### Conclusion: there's not leak, I confused allocs growing nature.

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 120 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 75 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 75 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 75 KiB

View File

@@ -11,6 +11,7 @@ services:
- "8080:8080"
- "8081:8081"
- "8081:8081/udp"
- "6060:6060"
srt:
build:

View File

@@ -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"`

View File

@@ -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
},