github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/benchmark/internal/loadgen/render.go (about) 1 package loadgen 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "net/http" 7 "time" 8 9 "github.com/sirupsen/logrus" 10 ) 11 12 var defaultRenderInterval = 1 * time.Minute 13 14 func (l *LoadGen) startRenderThread(done chan struct{}) { 15 ticker := time.NewTicker(defaultRenderInterval) 16 for { 17 select { 18 case <-done: 19 return 20 case <-ticker.C: 21 logrus.Info("calling render endpoint under load") 22 l.callRenderEndpoint() 23 24 logrus.Info("calling render endpoint without load") 25 l.pauseMutex.Lock() 26 l.callRenderEndpoint() 27 l.pauseMutex.Unlock() 28 } 29 } 30 } 31 32 func (l *LoadGen) callRenderEndpoint() { 33 url := fmt.Sprintf( 34 "%s/render?from=now-%dh&until=now&query=%s%%7B%%7D&max-nodes=1024&format=json", 35 l.Config.ServerAddress, 36 l.duration/time.Hour, 37 l.renderAppName, 38 ) 39 for i := 0; i < 1; i++ { 40 st := time.Now() 41 client := http.Client{ 42 Timeout: 360 * time.Second, 43 } 44 req, err := client.Get(url) 45 // req, err := http.Get(url) 46 if req != nil && req.Body != nil && err == nil { 47 b, err := ioutil.ReadAll(req.Body) 48 l := 100 49 if len(b) < l { 50 l = len(b) 51 } 52 logrus.Debug("body", string(b[:l]), err) 53 } 54 logrus.Infof("render req %d time %q %q", i, time.Now().Sub(st), err) 55 } 56 }