Using the free and opensource tool Draw IO app draw a diagram worker-pool app from the last exercise being scheduled by the Go Scheduler
Using the provided main.go
file, add pprof and explore the memory insights of a single process Go app.
If you are completing this on your own, here are some helpful videos:
add pprof server to your text parsing app. First add the pprof driver to your app.
import _ "net/http/pprof"
NOTE: the "_" means that the import is added globally as a backend system. This is common for servers, db drivers, etc
add a pprof server as it's own goroutine in your main function.
// run pprof
go func() {
http.ListenAndServe("localhost:6060", nil)
}()
NOTE: When you do a default ListenAndServe()
to spin up your server, your pprof is open to the public internet. To add protections use a mux.Server()
for a custom server and you basic security precautions.
install graphviz on your machine to get the visual insights.
Mac:
brew install graphviz
run pprof while your worker-pool is executing
go tool pprof -http=:18080 http://localhost:6060/debug/pprof/profile?seconds=30
In the default graph each node is a function that your program is running. Size and color indicate how much cpu and time each function is taking.
To acces the commandline tool tool run:
go tool pprof http://localhost:6060/debug/pprof/allocs
in the command line tool you can search for functions like this
(pprof) list worker
The functions will provide insights in the following categories:
- allocs: A sampling of all past heap memory allocations
- heap: A sampling of heap memory allocations of live objects.
- profile: CPU profile.
- goroutine: Stack traces of all current goroutines.
- block: Stack traces that led to blocking on synchronization primitives
- cmdline: The command line invocation of the current program
- mutex: Stack traces of holders of contended mutexes
- threadcreate: Stack traces that led to the creation of new OS threads
- trace: A trace of execution of the current program.
Take some time to expore pprof. Be able to answer the following questions:
- What function takes the most time?
- What function take the most cpu?
- What function takes the most memory?
- Are any funcitons inlined?