Skip to content

Instantly share code, notes, and snippets.

@DanielMorsing
Created January 31, 2016 18:07
Show Gist options
  • Save DanielMorsing/c357f15c96afef0fdb76 to your computer and use it in GitHub Desktop.
Save DanielMorsing/c357f15c96afef0fdb76 to your computer and use it in GitHub Desktop.
the program
package main
import (
"runtime/causalprof"
"net/http"
"bufio"
"os"
"math/rand"
"fmt"
"sync/atomic"
)
func main() {
http.HandleFunc("/", randomHandler)
go http.ListenAndServe(":9090", nil)
select{}
causalprof.Stop()
}
var reqcount int64
func randomHandler(w http.ResponseWriter, req *http.Request) {
rq := atomic.AddInt64(&reqcount, 1)
if rq == 50000 {
causalprof.Start(os.Stdout)
}
p := causalprof.StartProgress()
buffered := bufio.NewWriter(w)
w.Header().Set("Content-Length", "20000")
for i := 0; i < 10000; i++ {
fmt.Fprintln(buffered, rand.Int63n(10))
}
buffered.Flush()
p.Stop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment