Skip to content

Latest commit

 

History

History
94 lines (69 loc) · 3.25 KB

README.md

File metadata and controls

94 lines (69 loc) · 3.25 KB

Exercise 1 - Draw Go Scheduler

Part 1 - scheduling a single process go app:

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

Part 2 - Add pprof to your Go App:

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:

Step 1:

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

Step 2:

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.

Step 3:

install graphviz on your machine to get the visual insights.

Mac:

brew install graphviz

Step 4:

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.

Step 5:

Take some time to expore pprof. Be able to answer the following questions:

  1. What function takes the most time?
  2. What function take the most cpu?
  3. What function takes the most memory?
  4. Are any funcitons inlined?

Resources: