-
-
Save desa/075832fd09ce57f57e6f307f5c197eea to your computer and use it in GitHub Desktop.
Repro Script for Influxd Panic
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 ( | |
"bytes" | |
"fmt" | |
"net/http" | |
"time" | |
"github.com/influxdata/influx-stress/lineprotocol" | |
"github.com/influxdata/influx-stress/write" | |
) | |
type point struct { | |
seriesKey []byte | |
N *lineprotocol.Int | |
time *lineprotocol.Timestamp | |
fields []lineprotocol.Field | |
} | |
func newPoint(sk []byte, p lineprotocol.Precision) *point { | |
fields := make([]lineprotocol.Field, 1) | |
e := &point{ | |
seriesKey: sk, | |
time: lineprotocol.NewTimestamp(p), | |
fields: fields, | |
} | |
n := &lineprotocol.Int{Key: []byte("n")} | |
e.N = n | |
e.fields[0] = n | |
return e | |
} | |
func (p *point) Series() []byte { | |
return p.seriesKey | |
} | |
func (p *point) Fields() []lineprotocol.Field { | |
return p.fields | |
} | |
func (p *point) Time() *lineprotocol.Timestamp { | |
return p.time | |
} | |
func style(tmpl string) []*point { | |
pts := make([]*point, 0, 100000) | |
for i := 0; i < 100; i++ { | |
for j := 0; j < 100; j++ { | |
for k := 0; k < 10; k++ { | |
pt := newPoint([]byte(fmt.Sprintf(tmpl, i, j, k)), lineprotocol.Nanosecond) | |
pts = append(pts, pt) | |
} | |
} | |
} | |
return pts | |
} | |
func showSeries(addr string) time.Duration { | |
t := time.Now() | |
http.Get(fmt.Sprintf("http://%v:8086/query?db=stress&q=show+series", addr)) | |
return time.Since(t) | |
} | |
func avg(ts []time.Duration) time.Duration { | |
var total time.Duration | |
for _, t := range ts { | |
total += t | |
} | |
return total / time.Duration(len(ts)) | |
} | |
func max(ts []time.Duration) time.Duration { | |
var m time.Duration | |
for _, t := range ts { | |
if t > m { | |
m = t | |
} | |
} | |
return m | |
} | |
func min(ts []time.Duration) time.Duration { | |
var m time.Duration = 1 * time.Second | |
for _, t := range ts { | |
if t < m { | |
m = t | |
} | |
} | |
return m | |
} | |
func median(ts []time.Duration) time.Duration { | |
return ts[len(ts)/2] | |
} | |
func test(tmpl, addr string) { | |
http.Get(fmt.Sprintf("http://%v:8086/query?q=create+database+stress", addr)) | |
c := write.NewClient(fmt.Sprintf("http://%v:8086", addr), "stress", "", "n") | |
buf := bytes.NewBuffer(nil) | |
stdPts := style(tmpl) | |
t := time.Now() | |
for i, pt := range stdPts { | |
pt.time.Time = t | |
lineprotocol.WritePoint(buf, pt) | |
if (i+1)%10000 == 0 { | |
c.Send(buf.Bytes()) | |
} | |
} | |
ts := []time.Duration{} | |
for i := 0; i < 1000; i++ { | |
ts = append(ts, showSeries(addr)) | |
} | |
fmt.Printf("Format: %v\n", tmpl) | |
fmt.Printf("Max: %v\n", max(ts)) | |
fmt.Printf("Avg: %v\n", avg(ts)) | |
fmt.Printf("Min: %v\n", min(ts)) | |
fmt.Printf("Median: %v\n", median(ts)) | |
fmt.Println() | |
http.Get(fmt.Sprintf("http://%v:8086/query?q=drop+database+stress", addr)) | |
} | |
func main() { | |
host := "localhost" | |
test("cpu.a=%v.b=%v.c=%v", host) | |
time.Sleep(10 * time.Second) | |
test("cpu,a=%v,b=%v,c=%v", host) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment