Skip to content

Instantly share code, notes, and snippets.

@ascandella
Last active February 16, 2017 15:38
Show Gist options
  • Save ascandella/b262e56d2165c5d6a7cff581a3051c74 to your computer and use it in GitHub Desktop.
Save ascandella/b262e56d2165c5d6a7cff581a3051c74 to your computer and use it in GitHub Desktop.
Sample pprof app
package main
import (
"fmt"
"io/ioutil"
"math/rand"
"net/http"
_ "net/http/pprof"
"sync"
"time"
)
const _numWorkers int32 = 100000
func intensiveWork(n int32) {
v := rand.Int31n(n)
time.Sleep(time.Duration(v) * time.Millisecond)
fmt.Fprintf(ioutil.Discard, fmt.Sprintf("%v", n<<31))
}
func main() {
// Start the pprof server
go func() {
fmt.Println(http.ListenAndServe(":6060", nil))
}()
wg := sync.WaitGroup{}
for i := int32(1); i <= _numWorkers; i++ {
i := i
wg.Add(1)
go func(i int32) {
intensiveWork(i)
wg.Done()
}(i)
}
wg.Wait()
fmt.Println("Done")
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment