Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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