Last active
February 16, 2017 15:38
-
-
Save ascandella/b262e56d2165c5d6a7cff581a3051c74 to your computer and use it in GitHub Desktop.
Sample pprof app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment